diff options
author | Fabrice Bellard <fabrice@bellard.org> | 2025-03-25 16:01:40 +0100 |
---|---|---|
committer | Fabrice Bellard <fabrice@bellard.org> | 2025-03-25 16:01:40 +0100 |
commit | 156d981afeb07d7520ad75685e15b8dabd95f35a (patch) | |
tree | f7de0796d6df17ec8d8d12834dd0cce5d6c78892 /tests | |
parent | 372ad84e9a940b94678a3102d015d2f684dd9097 (diff) | |
download | quickjs-156d981afeb07d7520ad75685e15b8dabd95f35a.tar.gz quickjs-156d981afeb07d7520ad75685e15b8dabd95f35a.zip |
added string ropes for faster concatenation of long strings (issue #67)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/microbench.js | 28 | ||||
-rw-r--r-- | tests/test_builtin.js | 27 |
2 files changed, 55 insertions, 0 deletions
diff --git a/tests/microbench.js b/tests/microbench.js index 4f69c40..7397ad9 100644 --- a/tests/microbench.js +++ b/tests/microbench.js @@ -957,6 +957,32 @@ function string_build4(n) return n * 1000; } +/* append */ +function string_build_large1(n) +{ + var i, j, r, len = 20000; + for(j = 0; j < n; j++) { + r = ""; + for(i = 0; i < len; i++) + r += "abcdef"; + global_res = r; + } + return n * len; +} + +/* prepend */ +function string_build_large2(n) +{ + var i, j, r, len = 20000; + for(j = 0; j < n; j++) { + r = ""; + for(i = 0; i < len; i++) + r = "abcdef" + r; + global_res = r; + } + return n * len; +} + /* sort bench */ function sort_bench(text) { @@ -1336,6 +1362,8 @@ function main(argc, argv, g) string_build2, string_build3, string_build4, + string_build_large1, + string_build_large2, int_to_string, int_toString, float_to_string, diff --git a/tests/test_builtin.js b/tests/test_builtin.js index 1de89ed..383d577 100644 --- a/tests/test_builtin.js +++ b/tests/test_builtin.js @@ -864,6 +864,32 @@ function test_generator() assert(v.value === 6 && v.done === true); } +function rope_concat(n, dir) +{ + var i, s; + s = ""; + if (dir > 0) { + for(i = 0; i < n; i++) + s += String.fromCharCode(i & 0xffff); + } else { + for(i = n - 1; i >= 0; i--) + s = String.fromCharCode(i & 0xffff) + s; + } + + for(i = 0; i < n; i++) { + /* test before the assert to go faster */ + if (s.charCodeAt(i) != (i & 0xffff)) { + assert(s.charCodeAt(i), i & 0xffff); + } + } +} + +function test_rope() +{ + rope_concat(100000, 1); + rope_concat(100000, -1); +} + test(); test_function(); test_enum(); @@ -880,3 +906,4 @@ test_symbol(); test_map(); test_weak_map(); test_generator(); +test_rope(); |