← Commit history

test: migrate ashvm benchmarks to Java-like Ash

lennoxrose committed on Oct 18, 2026 at 00:42 UTC

e290a79parent67d5996

6 files changed+86−37

hearth/ashvm/benchmarks/countdown.ashmodified

+12−6
@@ -1,7 +1,13 @@
1-local i = 20000000;
2-local count = 0;
3-during (i > 0) {
4- local count = count + 1;
5- local i = i - 1;
1+package benchmarks;
2+
3+class Countdown {
4+ public static void main(String[] args) {
5+ int i = 20000000;
6+ int count = 0;
7+ while (i > 0) {
8+ count = count + 1;
9+ i = i - 1;
10+ }
11+ System.out.println(count);
12+ }
613 }
7-say count;

hearth/ashvm/benchmarks/fib.ashmodified

+12−5
@@ -1,7 +1,14 @@
1-forge fib(n) {
2- given (n < 2) {
3- yield n;
1+package benchmarks;
2+
3+class Fib {
4+ static int fib(int n) {
5+ if (n < 2) {
6+ return n;
7+ }
8+ return fib(n - 1) + fib(n - 2);
9+ }
10+
11+ public static void main(String[] args) {
12+ System.out.println(fib(30));
413 }
5- yield fib(n - 1) + fib(n - 2);
614 }
7-say fib(30);

hearth/ashvm/benchmarks/fib20.ashmodified

+14−1
@@ -1 +1,14 @@
1-forge fib(n) { given (n < 2) { yield n; } yield fib(n-1)+fib(n-2); } say fib(20);
1+package benchmarks;
2+
3+class Fib20 {
4+ static int fib(int n) {
5+ if (n < 2) {
6+ return n;
7+ }
8+ return fib(n - 1) + fib(n - 2);
9+ }
10+
11+ public static void main(String[] args) {
12+ System.out.println(fib(20));
13+ }
14+}

hearth/ashvm/benchmarks/hashmap.ashmodified

+23−12
@@ -1,13 +1,24 @@
1-local m = {};
2-local i = 0;
3-during (i < 50000) {
4- m[str(i)] = i * 2;
5- local i = i + 1;
1+package benchmarks;
2+
3+import ash.util.HashMap;
4+
5+class HashMapBench {
6+ public static void main(String[] args) {
7+ HashMap<String, Integer> m = new HashMap<>();
8+ int i = 0;
9+ while (i < 50000) {
10+ m.put(String.valueOf(i), i * 2);
11+ i = i + 1;
12+ }
13+ int j = 0;
14+ int total = 0;
15+ while (j < 50000) {
16+ Integer? v = m.get(String.valueOf(j));
17+ if (v != null) {
18+ total = total + v;
19+ }
20+ j = j + 1;
21+ }
22+ System.out.println(total);
23+ }
624 }
7-local j = 0;
8-local total = 0;
9-during (j < 50000) {
10- local total = total + m[str(j)];
11- local j = j + 1;
12-}
13-say total;

hearth/ashvm/benchmarks/loop.ashmodified

+12−6
@@ -1,7 +1,13 @@
1-local sum = 0;
2-local i = 0;
3-during (i < 20000000) {
4- local sum = sum + i;
5- local i = i + 1;
1+package benchmarks;
2+
3+class Loop {
4+ public static void main(String[] args) {
5+ int sum = 0;
6+ int i = 0;
7+ while (i < 20000000) {
8+ sum = sum + i;
9+ i = i + 1;
10+ }
11+ System.out.println(sum);
12+ }
613 }
7-say sum;

hearth/ashvm/benchmarks/loop_varbound.ashmodified

+13−7
@@ -1,8 +1,14 @@
1-local n = 20000000;
2-local sum = 0;
3-local i = 0;
4-during (i < n) {
5- local sum = sum + i;
6- local i = i + 1;
1+package benchmarks;
2+
3+class LoopVarbound {
4+ public static void main(String[] args) {
5+ int n = 20000000;
6+ int sum = 0;
7+ int i = 0;
8+ while (i < n) {
9+ sum = sum + i;
10+ i = i + 1;
11+ }
12+ System.out.println(sum);
13+ }
714 }
8-say sum;