summaryrefslogtreecommitdiff
path: root/bench/regex-match.myr
diff options
context:
space:
mode:
Diffstat (limited to 'bench/regex-match.myr')
-rw-r--r--bench/regex-match.myr36
1 files changed, 23 insertions, 13 deletions
diff --git a/bench/regex-match.myr b/bench/regex-match.myr
index 47c9264..dd78860 100644
--- a/bench/regex-match.myr
+++ b/bench/regex-match.myr
@@ -1,26 +1,36 @@
use std
use regex
+use testr
-const main = {
- var str, re, i
+var str
+var dotstar, hello
- str = "€i²æ&±-ŝ€i²æ&±-ŝ€i²æ&±-ŝ€i²æ&±-ŝ€i²æ&±-ŝüüü€i²æ&±-ŝüüü€i²æ&±-ŝü"
+const main = {
+ str = std.sldup("hello world!")
str = std.strcat(str, str)
str = std.strcat(str, str)
str = std.strcat(str, str)
str = std.strcat(str, str)
- for i = 0; i < 100; i++
- match regex.compile(".*")
- | `std.Ok r: re = r
- | `std.Err m: std.fatal("couldn't compile regex: %s\n", m)
- ;;
+ dotstar = std.try(regex.compile(".*"))
+ hello = std.try(regex.compile("hel*o"))
+
+ testr.bench([
+ [.name="matchall", .fn=matchall],
+ [.name="searchhello", .fn=searchhello],
+ ][:])
+}
- match regex.exec(re, str)
- | `std.Some m:
- | `std.None: std.fatal("Didn't match regex\n")
- ;;
+const matchall = {ctx
+ match regex.exec(dotstar, str)
+ | `std.Some m: regex.matchfree(m)
+ | `std.None: std.fatal("Didn't match regex\n")
+ ;;
+}
- regex.free(re)
+const searchhello = {ctx
+ match regex.search(dotstar, str)
+ | `std.Some m: regex.matchfree(m)
+ | `std.None: std.fatal("Didn't match regex\n")
;;
}