Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F3053722
non_async_loop_repro.js
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
non_async_loop_repro.js
View Options
const
TOTAL
=
Number
(
process
.
env
.
TOTAL
||
5000000
);
const
MODE
=
process
.
env
.
MODE
||
"routeSync"
;
function
nowMs
()
{
return
performance
.
now
();
}
function
makeContext
()
{
return
{
finalized
:
false
,
req
:
{
routeIndex
:
-
1
},
res
:
null
,
text
(
body
,
status
=
200
)
{
this
.
finalized
=
true
;
this
.
res
=
{
body
,
status
};
return
this
.
res
;
}
};
}
function
routeSync
(
c
)
{
return
c
.
text
(
"ok"
);
}
function
runTightLoop
()
{
let
acc
=
0
;
for
(
let
i
=
0
;
i
<
TOTAL
;
i
++
)
{
acc
+=
i
;
}
return
acc
;
}
function
runRouteSyncLoop
()
{
let
finalized
=
0
;
for
(
let
i
=
0
;
i
<
TOTAL
;
i
++
)
{
const
ctx
=
makeContext
();
routeSync
(
ctx
);
if
(
ctx
.
finalized
)
finalized
++
;
}
return
finalized
;
}
function
main
()
{
const
startedAt
=
nowMs
();
const
result
=
MODE
===
"tightLoop"
?
runTightLoop
()
:
runRouteSyncLoop
();
const
elapsedMs
=
nowMs
()
-
startedAt
;
console
.
log
(
`mode=
${
MODE
}
`
);
console
.
log
(
`total=
${
TOTAL
}
`
);
console
.
log
(
`elapsed_ms=
${
elapsedMs
.
toFixed
(
3
)
}
`
);
console
.
log
(
`ops_per_sec=
${
(
TOTAL
/
(
elapsedMs
/
1000
)).
toFixed
(
1
)
}
`
);
console
.
log
(
`result=
${
result
}
`
);
}
main
();
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Fri, Apr 3, 4:11 PM (2 d)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
521427
Default Alt Text
non_async_loop_repro.js (1 KB)
Attached To
Mode
rANT Ant
Attached
Detach File
Event Timeline
Log In to Comment