-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: Add benchmark and speedup (#37)
Fixes #36 at least to some extent! Throwing a non-`Error` subclass makes the Fibonacci benchmark ~6x faster: -Time elapsed (ms): 60459 +Time elapsed (ms): 10152 The difference for the 40th Fibonacci number is even more dramatic, ~2000s → 200s. Still slower than jlox's 27 seconds, but at least within an order of magnitude. Thanks to https://github.com/davidhfriedman/jslox for the inspiration.
- Loading branch information
Showing
4 changed files
with
25 additions
and
2 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,10 @@ | ||
fun fib(n) { | ||
if (n < 2) return n; | ||
return fib(n - 1) + fib(n - 2); | ||
} | ||
|
||
var before = clock(); | ||
print fib(40); | ||
var after = clock(); | ||
print "Time elapsed (ms):"; | ||
print after - before; |
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,10 @@ | ||
fun fib(n) { | ||
if (n < 2) return n; | ||
return fib(n - 1) + fib(n - 2); | ||
} | ||
|
||
var before = clock(); | ||
print fib(33); | ||
var after = clock(); | ||
print "Time elapsed (ms):"; | ||
print after - before; |
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
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