1616COLD_ROUNDS = 5 # tests that create a new sandbox each time
1717WARM_ROUNDS = 10 # tests that reuse an existing sandbox
1818
19- # ── Helpers ──────────────────────────────────────────────────────────
19+ # -- Helpers ----------------------------------------------------------
2020
2121
2222def measure_n (fn , n ):
@@ -32,7 +32,7 @@ def measure_n(fn, n):
3232
3333
3434def fmt (stats ):
35- """Format stats as 'avg ms (min=… , max=… )'."""
35+ """Format stats as 'avg ms (min=... , max=... )'."""
3636 return f"{ stats ['avg' ]:>7.1f} ms (min={ stats ['min' ]:.1f} , max={ stats ['max' ]:.1f} )"
3737
3838
@@ -45,9 +45,9 @@ def run_suite(name, backend, module=None, lang="python"):
4545 """Run all benchmarks for one backend configuration."""
4646 from hyperlight_sandbox import Sandbox
4747
48- print (f"\n { '═ ' * 70 } " )
48+ print (f"\n { '= ' * 70 } " )
4949 print (f" { name } ({ COLD_ROUNDS } cold / { WARM_ROUNDS } warm rounds)" )
50- print (f"{ '═ ' * 70 } " )
50+ print (f"{ '= ' * 70 } " )
5151
5252 hello = 'print("hello")' if lang == "python" else 'console.log("hello")'
5353 tool_code = (
@@ -67,7 +67,7 @@ def run_suite(name, backend, module=None, lang="python"):
6767
6868 results = {}
6969
70- # ── 1. Cold start: create + first run ────────────────────────
70+ # -- 1. Cold start: create + first run ------------------------
7171 def cold_start ():
7272 s = Sandbox (** kwargs )
7373 r = s .run (hello )
@@ -78,12 +78,12 @@ def cold_start():
7878 results ["Cold start (create + first run)" ] = stats
7979 print (f" Cold start (create + first run): { fmt (stats )} " )
8080
81- # ── 2. Warm run (no restore) ───────────────────────────────
81+ # -- 2. Warm run (no restore) -------------------------------
8282 _ , stats = measure_n (lambda : sandbox .run (hello ), WARM_ROUNDS )
8383 results ["Warm run (no restore)" ] = stats
8484 print (f" Warm run (no restore): { fmt (stats )} " )
8585
86- # ── 3. Cold start + tool dispatch ────────────────────────────
86+ # -- 3. Cold start + tool dispatch ----------------------------
8787 def with_tools ():
8888 s = Sandbox (** kwargs )
8989 s .register_tool ("add" , lambda a = 0 , b = 0 : a + b )
@@ -95,15 +95,15 @@ def with_tools():
9595 results ["Cold start + tool dispatch" ] = stats
9696 print (f" Cold start + tool dispatch: { fmt (stats )} " )
9797
98- # ── 4. Warm tool dispatch (no restore) ────────────────────────
98+ # -- 4. Warm tool dispatch (no restore) ------------------------
9999 warm_tool_sandbox = Sandbox (** kwargs )
100100 warm_tool_sandbox .register_tool ("add" , lambda a = 0 , b = 0 : a + b )
101101 warm_tool_sandbox .run (hello ) # warm up
102102 _ , stats = measure_n (lambda : warm_tool_sandbox .run (tool_code ), WARM_ROUNDS )
103103 results ["Warm tool dispatch (no restore)" ] = stats
104104 print (f" Warm tool dispatch (no restore): { fmt (stats )} " )
105105
106- # ── 5. File I/O ──────────────────────────────────────────────
106+ # -- 5. File I/O ----------------------------------------------
107107 if file_code :
108108
109109 def with_files ():
@@ -127,7 +127,7 @@ def with_files():
127127 results ["Warm file I/O (no restore)" ] = None
128128 print (" File I/O: n/a (not supported)" )
129129
130- # ── 6. Snapshot (create sandbox, run, then time just the snapshot) ──
130+ # -- 6. Snapshot (create sandbox, run, then time just the snapshot) --
131131 def one_snapshot ():
132132 s = Sandbox (** kwargs )
133133 s .register_tool ("add" , lambda a = 0 , b = 0 : a + b )
@@ -145,7 +145,7 @@ def one_snapshot():
145145 results ["Snapshot" ] = stats
146146 print (f" Snapshot: { fmt (stats )} " )
147147
148- # ── 7. Restore (create sandbox, snapshot, then time just the restore) ──
148+ # -- 7. Restore (create sandbox, snapshot, then time just the restore) --
149149 def one_restore ():
150150 s = Sandbox (** kwargs )
151151 s .register_tool ("add" , lambda a = 0 , b = 0 : a + b )
@@ -164,7 +164,7 @@ def one_restore():
164164 results ["Restore" ] = stats
165165 print (f" Restore: { fmt (stats )} " )
166166
167- # ── 8. Restore + run ─────────────────────────────────────────
167+ # -- 8. Restore + run -----------------------------------------
168168 snap_sandbox = Sandbox (** kwargs )
169169 snap_sandbox .register_tool ("add" , lambda a = 0 , b = 0 : a + b )
170170 snap_sandbox .run (hello )
@@ -179,7 +179,7 @@ def restore_and_run():
179179 results ["Restore + run" ] = stats
180180 print (f" Restore + run: { fmt (stats )} " )
181181
182- # ── 9. Restore + tool dispatch ───────────────────────────────
182+ # -- 9. Restore + tool dispatch -------------------------------
183183 def restore_and_tool ():
184184 snap_sandbox .restore (snap )
185185 return snap_sandbox .run (tool_code )
@@ -191,7 +191,7 @@ def restore_and_tool():
191191 return results
192192
193193
194- # ── Main ─────────────────────────────────────────────────────────────
194+ # -- Main -------------------------------------------------------------
195195
196196
197197def main ():
@@ -218,28 +218,28 @@ def main():
218218 except Exception as e :
219219 print (f" [warn] Skipped: { e } " )
220220
221- # ── Summary table (averages) ─────────────────────────────────
221+ # -- Summary table (averages) ---------------------------------
222222 if all_results :
223- print (f"\n { '═ ' * 90 } " )
223+ print (f"\n { '= ' * 90 } " )
224224 print (" Summary (avg ms)" )
225- print (f"{ '═ ' * 90 } " )
225+ print (f"{ '= ' * 90 } " )
226226
227227 backends = list (all_results .keys ())
228228 steps = list (next (iter (all_results .values ())).keys ())
229229
230230 header = f"{ 'Step' :<35} " + "" .join (f"{ b :>18} " for b in backends )
231231 print (header )
232- print ("─ " * len (header ))
232+ print ("- " * len (header ))
233233 for step in steps :
234234 row = f"{ step :<35} "
235235 for b in backends :
236236 s = all_results [b ].get (step )
237237 row += f"{ fmt_short (s ) if s else 'n/a' :>18} "
238238 print (row )
239239
240- print (f"\n { '═ ' * 90 } " )
240+ print (f"\n { '= ' * 90 } " )
241241 print (f" Done! ({ COLD_ROUNDS } cold / { WARM_ROUNDS } warm rounds per test)" )
242- print (f"{ '═ ' * 90 } " )
242+ print (f"{ '= ' * 90 } " )
243243
244244
245245if __name__ == "__main__" :
0 commit comments