Skip to content

Commit

Permalink
Add float benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
XuJiandong committed Oct 17, 2023
1 parent 3f09b7a commit 55ea958
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
9 changes: 7 additions & 2 deletions tests/basic/test_float.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ function assert(actual, expected, message) {
if (arguments.length == 1)
expected = true;

if (actual == expected)
if (actual === expected)
return;

if (actual !== null && expected !== null
&& typeof actual == 'object' && typeof expected == 'object'
&& actual.toString() === expected.toString())
return;

throw Error("assertion failed: got |" + actual + "|" +
Expand All @@ -14,7 +19,7 @@ function assert(actual, expected, message) {

function test_to_string() {
assert(1.1.toString(), "1.1")
assert(-1.1.toString(), "-1.100000")
assert((-1.1).toString(), "-1.1")
assert(3.14159265354.toString(), "3.1415926540000000")
}

Expand Down
9 changes: 2 additions & 7 deletions tests/benchmark/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,6 @@ function int_to_string(n) {
return n;
}

// TODO
function float_to_string(n) {
var s, r, j;
r = 0;
Expand Down Expand Up @@ -596,8 +595,7 @@ function json_stringify_bench(_) {
'isStudent': false,
'grades': [80, 90, 95],
'address': {'street': '123 ABC Street', 'city': 'Example City', 'country': 'USA'},
// TODO: into float
'height': 6,
'height': 5.9,
'skills': ['JavaScript', 'Python', 'HTML', 'CSS'],
'isActive': true
};
Expand Down Expand Up @@ -638,10 +636,7 @@ const BENCH_LIST = [
{'name': 'string_build3', 'func': string_build3},
{'name': 'string_build4', 'func': string_build4},
{'name': 'int_to_string', 'func': int_to_string},
// {
// "name": "float_to_string",
// "func": float_to_string,
// },
{'name': 'float_to_string', 'func': float_to_string},
{'name': 'string_to_int', 'func': string_to_int},
{'name': 'string_to_float', 'func': string_to_float},
{'name': 'sort_bench(5000 numbers)', 'func': sort_bench, 'bench_prepare': sort_prepare},
Expand Down
9 changes: 5 additions & 4 deletions tests/benchmark/benchmark.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ string_build2: 191 K cycles
string_build3: 189 K cycles
string_build4: 194 K cycles
int_to_string: 10 K cycles
float_to_string: 21 K cycles
string_to_int: 5 K cycles
string_to_float: 8 K cycles
sort_bench(5000 numbers): 23807 K cycles
sort_bench(5000 numbers): 23806 K cycles
json_parse_bench: 123 K cycles
json_stringify_bench: 175 K cycles
json_stringify_bench: 198 K cycles
Run result: 0
Total cycles consumed: 53483362(51.0M)
Transfer cycles: 123789(120.9K), running cycles: 53359573(50.9M)
Total cycles consumed: 53546530(51.1M)
Transfer cycles: 123824(120.9K), running cycles: 53422706(50.9M)

0 comments on commit 55ea958

Please sign in to comment.