Skip to content

Commit

Permalink
chore: Some benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
giann committed Feb 29, 2024
1 parent 6fb8d77 commit 86a0e64
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/bench/010-ackermann.buzz
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import "std";

fun main([str] args) > void {
const m = (if (args.len() > 0) parseInt(args[0]) else null) ?? 3;
const n = (if (args.len() > 1) parseInt(args[1]) else null) ?? 8;

print("result: {ack(m, n)}");
}

fun ack(int m, int n) > int {
if (m == 0) {
return n + 1;
}

if (n == 0) {
return ack(m: m - 1, n: 1);
}

return ack(
m: m - 1,
n: ack(m, n: n - 1)
);
}
38 changes: 38 additions & 0 deletions tests/bench/011-bubble-sort.buzz
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import "std";

fun main([str] args) > void {
const max = (if (args.len() > 0) parseInt(args[0]) else null) ?? 750;

var list = init(max);

bubblesort(list);

foreach (int e in list) {
print("{e}");
}
}

fun init(int max) > [int] {
[int] list = [];
const f = max - 13;
const h = ((max - 117) * (max - 13)) / max;

for (int i = 0; i < max; i = i + 1) {
list.append((f * i) % h - (h / 2));
}

return list;
}

fun bubblesort([int] list) > void {
const len = list.len();
for (int i = 0; i < len - 1; i = i + 1) {
for (int j = 0; j < len - 1; j = j + 1) {
if (list[j] > list[j + 1]) {
const tmp = list[j];
list[j] = list[j + 1];
list[j + 1] = tmp;
}
}
}
}

0 comments on commit 86a0e64

Please sign in to comment.