forked from e2b-dev/code-interpreter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmarking.py
More file actions
33 lines (23 loc) · 852 Bytes
/
benchmarking.py
File metadata and controls
33 lines (23 loc) · 852 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import time
from dotenv import load_dotenv
from e2b_code_interpreter.code_interpreter_sync import Sandbox
load_dotenv()
iterations = 10
create_sandbox_time = 0
first_exec_time = 0
second_exec_time = 0
for i in range(iterations):
print("Iteration:", i + 1)
start_time = time.time()
sandbox = Sandbox()
create_sandbox_time += time.time() - start_time
start_time = time.time()
sandbox.run_code("x = 1")
first_exec_time += time.time() - start_time
start_time = time.time()
result = sandbox.run_code("x+=1; x")
second_exec_time += time.time() - start_time
sandbox.kill()
print(f"Average Create Sandbox Time: {create_sandbox_time / iterations}s")
print(f"Average Execute Python x = 1 Time: {first_exec_time / iterations}s")
print(f"Average Execute Python x+=1; x Time: {second_exec_time / iterations}s")