Skip to content

Commit 4a43e8b

Browse files
committed
feat: Add macro benchmark for JSON parsing and micro benchmark for Fibonacci calculation.
1 parent 14f0d7b commit 4a43e8b

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

benchmarks/macro/json_bench.prox

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@ class JsonParser {
55
init(input) {
66
this.input = input;
77
this.pos = 0;
8-
this.len = length(input);
8+
this.len = len(input);
99
}
1010

11-
func peek() {
11+
peek() {
1212
if (this.pos >= this.len) return "";
1313
return substr(this.input, this.pos, 1);
1414
}
1515

16-
func consume() {
16+
consume() {
1717
if (this.pos >= this.len) return "";
1818
let c = substr(this.input, this.pos, 1);
1919
this.pos = this.pos + 1;
2020
return c;
2121
}
2222

23-
func parse() {
23+
parse() {
2424
this.skipWhitespace();
2525
let c = this.peek();
2626

@@ -31,7 +31,7 @@ class JsonParser {
3131
return this.parseString();
3232
}
3333

34-
func skipWhitespace() {
34+
skipWhitespace() {
3535
while (this.pos < this.len) {
3636
let c = this.peek();
3737
if (c == " " || c == "\n" || c == "\t") {
@@ -42,7 +42,7 @@ class JsonParser {
4242
}
4343
}
4444

45-
func parseObject() {
45+
parseObject() {
4646
this.consume(); // {
4747
let obj = {};
4848
this.skipWhitespace();
@@ -66,7 +66,7 @@ class JsonParser {
6666
return obj;
6767
}
6868

69-
func parseArray() {
69+
parseArray() {
7070
this.consume(); // [
7171
let arr = [];
7272
this.skipWhitespace();
@@ -84,7 +84,7 @@ class JsonParser {
8484
return arr;
8585
}
8686

87-
func parseString() {
87+
parseString() {
8888
this.consume(); // "
8989
let res = "";
9090
while (this.peek() != "\"") {
@@ -104,7 +104,7 @@ func main() {
104104
}
105105
json_str = json_str + "]}";
106106

107-
print("JSON Length: " + to_string(length(json_str)));
107+
print("JSON Length: " + to_string(len(json_str)));
108108

109109
let start = time();
110110

@@ -115,7 +115,7 @@ func main() {
115115

116116
// Check result
117117
let users = res["users"];
118-
print("Parsed " + to_string(length(users)) + " users");
118+
print("Parsed " + to_string(len(users)) + " users");
119119
print("Time: " + to_string(elapsed));
120120
}
121121

benchmarks/micro/fib.prox

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ func fib(n) {
55
}
66

77
func main() {
8-
let start = time();
8+
let start = clock();
99
print("Fibonacci(30): " + to_string(fib(30)));
10-
let elapsed = time() - start;
10+
let elapsed = clock() - start;
1111
print("Time: " + to_string(elapsed));
1212
}
1313

0 commit comments

Comments
 (0)