Language
JavaScript
Compiler
Node.js 14.0.0
Options
$ node prog.js
JavaScript parseInt() と Math.floor() のその速度比較
--------
parseInt( v ) の速度を計測
[
50.336700439453125,
48.38153076171875,
46.81078338623047,
165.11466217041016,
144.74008178710938
] ms.
--------
Math.floor( v ) の速度を計測
[
50.35356903076172,
49.59717559814453,
50.359703063964844,
48.49549865722656,
48.56394958496094
] ms.
--------
Math.trunc( v ) の速度を計測
[
50.605201721191406,
48.16987609863281,
46.18598937988281,
49.57775115966797,
50.44541931152344
] ms.
--------
v | 0 の速度を計測
[
46.15593719482422,
45.77650451660156,
60.35423278808594,
0,
0,
'-4294967293': NaN,
'-4294967292': NaN
] ms.
--------
結論 -> parseInt は 0付近のみ異常に遅い
{
node: '14.0.0',
v8: '8.1.307.30-node.30',
uv: '1.37.0',
zlib: '1.2.11',
brotli: '1.0.7',
ares: '1.16.0',
modules: '83',
nghttp2: '1.40.0',
napi: '6',
llhttp: '2.0.4',
openssl: '1.1.1f',
cldr: '36.1',
icu: '66.1',
tz: '2019c',
unicode: '13.0'
}
Exit Code:
0