aboutsummaryrefslogtreecommitdiff
path: root/tests/bench/selfmod.zc
diff options
context:
space:
mode:
authorGravatar Moon Flower <moonflower@elhenney.local> 2026-10-12 08:46:23 +0330
committerGravatar Moon Flower <moonflower@elhenney.local> 2026-10-12 08:46:23 +0330
commitecc350ca5c2eb50be8309c5f14f8bf0d87db9a02 (patch)
tree70e0af76a1b13affff7c6cc8aac7b3e6ef960478 /tests/bench/selfmod.zc
a
Diffstat (limited to 'tests/bench/selfmod.zc')
-rw-r--r--tests/bench/selfmod.zc19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/bench/selfmod.zc b/tests/bench/selfmod.zc
new file mode 100644
index 0000000..7e16fdb
--- /dev/null
+++ b/tests/bench/selfmod.zc
@@ -0,0 +1,19 @@
+// self-modifying code in a loop: each pass rewrites a literal inside g, so the
+// translation of g is dropped and made again, while a pile of other code stays
+// translated. prints the sum so the engines can be compared.
+int litw(int v) { return v + v + 1; }
+int g() { return 1000; }
+int work(int n) { int i = 0, s = 0; while (i < n) { s = s + i % 7; i++; } return s; }
+int a1() { return work(50); } int a2() { return work(60); } int a3() { return work(70); } int a4() { return a1() + a2(); }
+int main() {
+ word p = g; int i = 0, tot = 0;
+ while (*p != litw(1000)) p++;
+ a4(); a3();
+ while (i < 20000) {
+ *p = litw(i);
+ tot = tot + g() + a3();
+ i++;
+ }
+ put_n(tot); put_c(10);
+ return 0;
+}