Rename utf8/utf16 benchmark tests. NFC - Move the test code out of the benchmark directory. These were move there by mistake in #18258. Despite their name they are not part of `test_benchmark` (and we probably want to keep it that way since they are mostly tests TextDecoder which is a browser API). - Convert benchmark_utf8.cpp from C++ to C. - Rename tests files to match the names of the tests - Give the tests consistent names in test_core and test_browser
diff --git a/test/test_browser.py b/test/test_browser.py index 93c3cce..94a92a8 100644 --- a/test/test_browser.py +++ b/test/test_browser.py
@@ -4144,12 +4144,12 @@ self.run_browser('test.html', '/report_result?0') @also_with_pthreads - def test_utf8_textdecoder(self): - self.btest_exit('benchmark/benchmark_utf8.c', 0, cflags=['--embed-file', test_file('utf8_corpus.txt') + '@/utf8_corpus.txt']) + def test_utf8_bench(self): + self.btest_exit('test_utf8_bench.c', 0, cflags=['--embed-file', test_file('test_utf8_bench.txt') + '@/utf8_corpus.txt']) @also_with_pthreads - def test_utf16_textdecoder(self): - self.btest_exit('benchmark/benchmark_utf16.cpp', 0, cflags=['--embed-file', test_file('utf16_corpus.txt') + '@/utf16_corpus.txt', '-sEXPORTED_RUNTIME_METHODS=UTF16ToString,stringToUTF16,lengthBytesUTF16']) + def test_utf16_bench(self): + self.btest_exit('test_utf16_bench.c', 0, cflags=['--embed-file', test_file('test_utf16_bench.txt') + '@/utf16_corpus.txt', '-sEXPORTED_RUNTIME_METHODS=UTF16ToString,stringToUTF16,lengthBytesUTF16']) # Tests that it is possible to initialize and render WebGL content in a # pthread by using OffscreenCanvas.
diff --git a/test/test_core.py b/test/test_core.py index c795a54..209340c 100644 --- a/test/test_core.py +++ b/test/test_core.py
@@ -5791,8 +5791,8 @@ @with_both_text_decoder @also_without_bigint def test_utf8_bench(self): - self.cflags += ['--embed-file', test_file('utf8_corpus.txt') + '@/utf8_corpus.txt'] - self.do_runf('benchmark/benchmark_utf8.c', 'OK.') + self.cflags += ['--embed-file', test_file('test_utf8_bench.txt') + '@/utf8_corpus.txt'] + self.do_runf('test_utf8_bench.c', 'OK.') # Test that invalid character in UTF8 does not cause decoding to crash. @with_both_text_decoder @@ -5801,8 +5801,8 @@ self.do_runf('test_utf8_invalid.c', 'OK.') def test_utf16_bench(self): - self.cflags += ['--embed-file', test_file('utf16_corpus.txt') + '@/utf16_corpus.txt'] - self.do_runf('benchmark/benchmark_utf16.cpp', 'OK.') + self.cflags += ['--embed-file', test_file('test_utf16_bench.txt') + '@/utf16_corpus.txt'] + self.do_runf('test_utf16_bench.c', 'OK.') def test_wprintf(self): self.do_core_test('test_wprintf.cpp')
diff --git a/test/benchmark/benchmark_utf16.cpp b/test/test_utf16_bench.c similarity index 77% rename from test/benchmark/benchmark_utf16.cpp rename to test/test_utf16_bench.c index 8d33d61..0b78b0d 100644 --- a/test/benchmark/benchmark_utf16.cpp +++ b/test/test_utf16_bench.c
@@ -6,13 +6,13 @@ #include <stdio.h> #include <string.h> #include <wchar.h> -#include <iostream> -#include <cassert> +#include <stdio.h> +#include <assert.h> #include <emscripten.h> EM_JS_DEPS(deps, "$UTF16ToString"); -double test(const unsigned short *str) { +double test(const uint16_t *str) { double res = EM_ASM_DOUBLE({ var t0 = _emscripten_get_now(); var str = UTF16ToString($0); @@ -23,17 +23,16 @@ return res; } -unsigned short *utf16_corpus = 0; +uint16_t *utf16_corpus = 0; long utf16_corpus_length = 0; -unsigned short *randomString(int len) { +uint16_t *randomString(int len) { if (!utf16_corpus) { -// FILE *handle = fopen("ascii_corpus.txt", "rb"); FILE *handle = fopen("utf16_corpus.txt", "rb"); fseek(handle, 0, SEEK_END); utf16_corpus_length = ftell(handle)/2; assert(utf16_corpus_length > 0); - utf16_corpus = new unsigned short[utf16_corpus_length+1]; + utf16_corpus = malloc(sizeof(uint16_t) * (utf16_corpus_length+1)); fseek(handle, 0, SEEK_SET); fread(utf16_corpus, 2, utf16_corpus_length, handle); fclose(handle); @@ -45,10 +44,10 @@ if (startIdx + len > utf16_corpus_length) len = utf16_corpus_length - startIdx; } assert(len > 0); - unsigned short *s = new unsigned short[len+1]; + uint16_t *s = malloc(sizeof(uint16_t) * (len+1)); memcpy(s, utf16_corpus + startIdx, len*2); s[len] = 0; - while(((unsigned short)s[len-1] & 0xFF00) == 0xD800) { s[--len] = 0; } + while(((uint16_t)s[len-1] & 0xFF00) == 0xD800) { s[--len] = 0; } assert(len >= 0); return s; } @@ -58,9 +57,9 @@ double t2 = emscripten_get_now(); for(int i = 0; i < 10; ++i) { // FF Nightly: Already on small strings of 64 bytes in length, TextDecoder trumps in performance. - unsigned short *str = randomString(100); + uint16_t *str = randomString(100); t += test(str); - delete [] str; + free(str); } double t3 = emscripten_get_now(); printf("OK. Time: %f (%f).\n", t, t3-t2);
diff --git a/test/utf16_corpus.txt b/test/test_utf16_bench.txt similarity index 100% rename from test/utf16_corpus.txt rename to test/test_utf16_bench.txt Binary files differ
diff --git a/test/benchmark/benchmark_utf8.c b/test/test_utf8_bench.c similarity index 100% rename from test/benchmark/benchmark_utf8.c rename to test/test_utf8_bench.c
diff --git a/test/utf8_corpus.txt b/test/test_utf8_bench.txt similarity index 100% rename from test/utf8_corpus.txt rename to test/test_utf8_bench.txt