summaryrefslogtreecommitdiffstats
path: root/tests/assemble1.bench
diff options
context:
space:
mode:
authorKevin B Kenny <kennykb@acm.org>2010-09-25 14:51:11 (GMT)
committerKevin B Kenny <kennykb@acm.org>2010-09-25 14:51:11 (GMT)
commita65bf10cd7e281f19056e37d4bab5dae217c6394 (patch)
treebf7c48321b6cca5b3a99c8a02aba6441f406e92c /tests/assemble1.bench
parentb915b5fe069f09a9bd7dec58b31623b29133be2f (diff)
downloadtcl-a65bf10cd7e281f19056e37d4bab5dae217c6394.zip
tcl-a65bf10cd7e281f19056e37d4bab5dae217c6394.tar.gz
tcl-a65bf10cd7e281f19056e37d4bab5dae217c6394.tar.bz2
* tclAssembly.c: Massive refactoring of the assembler
* tclAssembly.h: to use a Tcl-like syntax (and use * tests/assemble.test: Tcl_ParseCommand to parse it). The * tests/assemble1.bench: refactoring also ensures that Tcl_Tokens in the assembler have string ranges inside the source code, which allows for [eval] and [expr] assembler directives that simply call TclCompileScript and TclCompileExpr recursively.
Diffstat (limited to 'tests/assemble1.bench')
-rw-r--r--tests/assemble1.bench113
1 files changed, 69 insertions, 44 deletions
diff --git a/tests/assemble1.bench b/tests/assemble1.bench
index 4f4dbce..18fd3a9 100644
--- a/tests/assemble1.bench
+++ b/tests/assemble1.bench
@@ -12,49 +12,74 @@ proc ulam1 {n} {
}
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
+set tcl_traceCompile 2; ulam1 1; set tcl_traceCompile 0
+
+proc ulam2 {n} {
+ tcl::unsupported::assemble {
+ load n; # max
+ dup; # max n
+ jump start; # max n
+
+ label loop; # max n
+ over 1; # max n max
+ over 1; # max in 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
+ }
+}
+set tcl_traceCompile 2; ulam2 1; set tcl_traceCompile 0
+
+proc test1 {n} {
+ for {set i 1} {$i <= $n} {incr i} {
+ ulam1 $i
+ }
+}
+proc test2 {n} {
+ for {set i 1} {$i <= $n} {incr i} {
+ ulam2 $i
+ }
+}
+
+for {set j 0} {$j < 10} {incr j} {
+ test1 1
+ set before [clock microseconds]
+ test1 30000
+ set after [clock microseconds]
+ puts "compiled: [expr {1e-6 * ($after - $before)}]"
-} {} code
-proc ulam2 n [list tcl::unsupported::assemble $code]
-set i 0
-puts [time {ulam2 [incr i]} 10000]
+ test2 1
+ set before [clock microseconds]
+ test2 30000
+ set after [clock microseconds]
+ puts "assembled: [expr {1e-6 * ($after - $before)}]"
+}
+ \ No newline at end of file