Skip to content

Commit

Permalink
tests: kmp, run performance test only if arg -benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
michaellilltokiwa committed Sep 6, 2024
1 parent 137a7b5 commit 9eb3fe0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
14 changes: 8 additions & 6 deletions tests/lib_knuth_morris_pratt/lib_knuth_morris_pratt.fz
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,19 @@ lib_knuth_morris_pratt =>
test_kmp(n i32) =>
("a"*2*n).utf8.find ("a"*n+"b").utf8

say (test_kmp 1000)

len := 250

if (envir.args.index_of "-benchmark")??

# for len=250 and interpreter takes ~70s on my machine
brute_force := time.stopwatch (()-> _:= test_brute_force len)
# for len=250 and interpreter takes ~1s on my machine
kmp := time.stopwatch (()-> _:= test_kmp len)
# for len=250 and interpreter takes ~70s on my machine
brute_force := time.stopwatch (()-> _:= test_brute_force len)
# for len=250 and interpreter takes ~1s on my machine
kmp := time.stopwatch (()-> _:= test_kmp len)

# check that kmp is at least four times faster
check (kmp*4 < brute_force)
# check that kmp is at least four times faster
check (kmp*4 < brute_force)


functionality
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
0
--nil--
0
--nil--

0 comments on commit 9eb3fe0

Please sign in to comment.