FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
emscripten/tests/benchmark_utf16.cpp at incoming · JavaScriptIOT/emscripten · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
JavaScriptIOT
/
emscripten
Public
forked from
emscripten-core/emscripten
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
emscripten
/
tests
/
benchmark_utf16.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
65 lines (60 loc) · 1.86 KB
Breadcrumbs
emscripten
/
tests
/
benchmark_utf16.cpp
Copy path
File metadata and controls
65 lines (60 loc) · 1.86 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#
include
<
stdio.h
>
#
include
<
string.h
>
#
include
<
wchar.h
>
#
include
<
iostream
>
#
include
<
cassert
>
#
include
<
emscripten.h
>
double
test
(
const
unsigned
short
*str) {
double
res =
EM_ASM_DOUBLE
({
var t0 =
_emscripten_get_now
();
var str = Module.
UTF16ToString
($
0
);
var t1 =
_emscripten_get_now
();
Module.
print
(
'
t:
'
+ (t1 - t0) +
'
, len(result):
'
+ str.
length
+
'
, result:
'
+ str.
slice
(
0
,
100
));
return
(t1-t0);
}, str);
return
res;
}
unsigned
short
*utf16_corpus =
0
;
long
utf16_corpus_length =
0
;
unsigned
short
*
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
];
fseek
(handle,
0
,
SEEK_SET
);
fread
(utf16_corpus,
2
, utf16_corpus_length, handle);
fclose
(handle);
utf16_corpus[utf16_corpus_length] =
0
;
}
int
startIdx =
rand
() % (utf16_corpus_length - len);
while
((utf16_corpus[startIdx] &
0xFF00
) ==
0xDC00
) {
++startIdx;
if
(startIdx + len > utf16_corpus_length) len = utf16_corpus_length - startIdx;
}
assert
(len >
0
);
unsigned
short
*s =
new
unsigned
short
[len+
1
];
memcpy
(s, utf16_corpus + startIdx, len*
2
);
s[len] =
0
;
while
(((
unsigned
short
)s[len-
1
] &
0xFF00
) ==
0xD800
) { s[--len] =
0
; }
assert
(len >=
0
);
return
s;
}
int
main
() {
srand
(
time
(
NULL
));
double
t =
0
;
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
);
t +=
test
(str);
free
(str);
}
double
t3 =
emscripten_get_now
();
printf
(
"
OK. Time: %f (%f).
\n
"
, t, t3-t2);
#
ifdef
REPORT_RESULT
REPORT_RESULT
(
0
);
#
endif
}
Back
|
FazBrowse Home
|
New Git URL