Language
JavaScript
Compiler
Node.js 14.0.0
Options
$ node prog.js
JavaScript parseInt() と Math.floor() のその速度比較
--------
parseInt( v ) の速度を計測
[
142.13645935058594,
46.32917785644531,
48.014381408691406,
46.321311950683594,
44.93146514892578
] ms.
--------
Math.floor( v ) の速度を計測
[
63.705787658691406,
45.713966369628906,
47.87810516357422,
45.74427032470703,
47.09394836425781
] ms.
--------
Math.trunc( v ) の速度を計測
[
51.691925048828125,
46.845542907714844,
47.7386474609375,
50.905799865722656,
46.82392883300781
] ms.
--------
v | 0 の速度を計測
[
50.077491760253906,
62.75060272216797,
43.862152099609375,
44.44807434082031,
45.2786865234375
] 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