-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a45f814
commit 3169dbd
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import asyncio | ||
import time | ||
|
||
from codeboxapi import CodeBox, ExecChunk | ||
|
||
|
||
def sync_stream_exec(cb: CodeBox) -> None: | ||
chunks: list[tuple[ExecChunk, float]] = [] | ||
t0 = time.perf_counter() | ||
for chunk in cb.stream_exec( | ||
"import time;\nfor i in range(3): time.sleep(1); print(i)" | ||
): | ||
chunks.append((chunk, time.perf_counter() - t0)) | ||
|
||
for chunk, t in chunks: | ||
print(f"{t:.5f}: {chunk}") | ||
|
||
|
||
async def async_stream_exec(cb: CodeBox) -> None: | ||
chunks: list[tuple[ExecChunk, float]] = [] | ||
t0 = time.perf_counter() | ||
async for chunk in cb.astream_exec( | ||
"import time;\nfor i in range(3): time.sleep(1); print(i)" | ||
): | ||
chunks.append((chunk, time.perf_counter() - t0)) | ||
|
||
for chunk, t in chunks: | ||
print(f"{t:.5f}: {chunk}") | ||
|
||
|
||
print("remote") | ||
cb = CodeBox() | ||
sync_stream_exec(cb) | ||
asyncio.run(async_stream_exec(cb)) | ||
|
||
print("local") | ||
local = CodeBox(api_key="local") | ||
sync_stream_exec(local) | ||
asyncio.run(async_stream_exec(local)) | ||
|
||
print("docker") | ||
docker = CodeBox(api_key="docker") | ||
sync_stream_exec(docker) | ||
asyncio.run(async_stream_exec(docker)) |