Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F10359890
perf.test.tsx
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
perf.test.tsx
View Options
import
assert
from
"node:assert"
;
import
{
TempstreamJSX
,
tempstream
}
from
"../src/index"
;
import
{
sleep
}
from
"./sleep"
;
describe
(
"performance"
,
()
=>
{
it
(
"handles a 300kb string-only document in less than 150% of the time it would take for a string-based approach"
,
async
()
=>
{
const
array
=
[];
for
(
let
i
=
0
;
i
<
180000
;
i
++
)
{
array
.
push
(
Math
.
random
());
}
const
time
=
Date
.
now
();
const
stream
=
(
<
body
>
{
array
.
map
(
async
(
number
)
=>
{
await
sleep
(
0
);
return
number
.
toString
();
})}
<
/body>
);
const
string
=
await
stream
;
const
stream_time
=
Date
.
now
()
-
time
;
const
time_str
=
Date
.
now
();
const
string2
=
`
<body>
${
(
await
Promise
.
all
(
array
.
map
(
async
(
number
)
=>
{
await
sleep
(
0
);
return
number
.
toString
();
}
)
)
).join("")}
</body>
`
;
const
string_time
=
Date
.
now
()
-
time_str
;
console
.
log
({
stream_time
,
string_time
});
assert
(
stream_time
<
string_time
*
1.5
);
});
it
(
"handles a 300kb Promise<Stream>-filled document in less than 300% of the time it would take for a string-based approach"
,
async
()
=>
{
const
array
=
[];
for
(
let
i
=
0
;
i
<
180000
;
i
++
)
{
array
.
push
(
Math
.
random
());
}
const
time
=
Date
.
now
();
const
stream
=
(
<
body
>
{
array
.
map
(
async
(
number
)
=>
{
await
sleep
(
0
);
return
tempstream
`
${
number
.
toString
()
}
`
;
})}
<
/body>
);
await
stream
;
const
stream_time
=
Date
.
now
()
-
time
;
const
time_str
=
Date
.
now
();
`
<body>
${
(
await
Promise
.
all
(
array
.
map
(
async
(
number
)
=>
{
await
sleep
(
0
);
return
number
.
toString
();
}
)
)
).join("")}
</body>
`
;
const
string_time
=
Date
.
now
()
-
time_str
;
console
.
log
({
stream_time
,
string_time
});
assert
(
stream_time
<
string_time
*
3
);
});
});
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Sat, Nov 8, 02:46 (15 h, 41 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1033951
Default Alt Text
perf.test.tsx (1 KB)
Attached To
Mode
rSTREAM tempstream
Attached
Detach File
Event Timeline
Log In to Comment