Skip to content

Instantly share code, notes, and snippets.

@chidiwilliams
Created June 21, 2022 10:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chidiwilliams/910e887fdbc9ec9a601493a9274572a2 to your computer and use it in GitHub Desktop.
Save chidiwilliams/910e887fdbc9ec9a601493a9274572a2 to your computer and use it in GitHub Desktop.
Benchmarks for glox (tree-walk interpreter) and clox (bytecode interpreter)
class Zoo {
init() {
this.aardvark = 1;
this.baboon = 1;
this.cat = 1;
this.donkey = 1;
this.elephant = 1;
this.fox = 1;
}
ant() { return this.aardvark; }
banana() { return this.baboon; }
tuna() { return this.cat; }
hay() { return this.donkey; }
grass() { return this.elephant; }
mouse() { return this.fox; }
}
var zoo = Zoo();
var sum = 0;
while (sum < 100000000) {
sum = sum + zoo.ant()
+ zoo.banana()
+ zoo.tuna()
+ zoo.hay()
+ zoo.grass()
+ zoo.mouse();
}
print sum;
Benchmark 1: clox bench.lox
Time (mean ± σ): 203.4 ms ± 4.8 ms [User: 200.3 ms, System: 1.5 ms]
Range (min … max): 197.7 ms … 212.6 ms 14 runs
Benchmark 2: glox -filePath bench.lox
Time (mean ± σ): 8.867 s ± 0.730 s [User: 8.930 s, System: 0.282 s]
Range (min … max): 7.774 s … 9.561 s 10 runs
Summary
'clox bench.lox' ran
43.59 ± 3.73 times faster than 'glox -filePath bench.lox'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment