Wandbox
SettingsLog
SettingsLog
Language
GitHubLogin
Ran/Viewed Log

Author

anonymous

over 3 years ago

Language

JavaScript

Compiler

Node.js 14.0.0

Options

Author

anonymous

over 3 years ago

$ node prog.js
JavaScript parseInt() と Math.floor() のその速度比較
--------
parseInt( v ) の速度を計測
[
  144.2425765991211,
  148.3888168334961,
  136.2340850830078,
  150.02034759521484,
  144.38919067382812
] ms.
--------
Math.floor( v ) の速度を計測
[
  164.4596176147461,
  165.74459838867188,
  171.30847930908203,
  166.59954833984375,
  164.39278411865234
] ms.
--------
Math.trunc( v ) の速度を計測
[
  183.10205078125,
  157.0017852783203,
  162.56234741210938,
  179.65151977539062,
  158.25049591064453
] ms.
--------
v | 0 の速度を計測
[
  171.83443450927734,
  154.78660583496094,
  155.2477035522461,
  171.82415008544922,
  158.69107055664062
] 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