summaryrefslogtreecommitdiffstats
path: root/tests/assemble1.bench
diff options
context:
space:
mode:
Diffstat (limited to 'tests/assemble1.bench')
-rw-r--r--tests/assemble1.bench60
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/assemble1.bench b/tests/assemble1.bench
new file mode 100644
index 0000000..4f4dbce
--- /dev/null
+++ b/tests/assemble1.bench
@@ -0,0 +1,60 @@
+proc ulam1 {n} {
+ set max $n
+ while {$n != 1} {
+ if {$n > $max} {
+ set max $n
+ }
+ if {$n % 2} {
+ set n [expr {3 * $n + 1}]
+ } else {
+ set n [expr {$n / 2}]
+ }
+ }
+ return $max
+}
+set i 0
+puts [time {ulam1 [incr i]} 10000]
+
+regsub -all {\#[^\n]*} {
+ {load n} # max
+ {dup} # max n
+ {jump start} # max n
+
+ {label loop} # max n
+ {over 1} # max n max
+ {over 1} # max n max n
+ {ge} # man n max>=n
+ {jumpTrue skip} # max n
+
+ {reverse 2} # n max
+ {pop} # n
+ {dup} # n n
+
+ {label skip} # max n
+ {dup} # max n n
+ {push 2} # max n n 2
+ {mod} # max n n%2
+ {jumpTrue odd} # max n
+
+ {push 2} # max n 2
+ {div} # max n/2 -> max n
+ {jump start} # max n
+
+ {label odd} # max n
+ {push 3} # max n 3
+ {mult} # max 3*n
+ {push 1} # max 3*n 1
+ {add} # max 3*n+1
+
+ {label start} # max n
+ {dup} # max n n
+ {push 1} # max n n 1
+ {neq} # max n n>1
+ {jumpTrue loop} # max n
+
+ {pop} # max
+
+} {} code
+proc ulam2 n [list tcl::unsupported::assemble $code]
+set i 0
+puts [time {ulam2 [incr i]} 10000]