JavaScript unit conversion benchmarks
Some benchmarks of community-made JavaScript/TypeScript libraries for converting units.
Generated automatically at Sat, 24 Aug 2024 16:11:27 GMT with Node.js v20.16.0 (V8 v11.3.244.8-node.23) on fv-az768-201 (Linux-x64 AMD EPYC 7763 64-Core Processor)
Each test was called 10,000 times to allow the runtime to warmup.
Afterward 100,000 trials were performed for each library.
Information about the execution times are shown below.
Lower execution times and higher executions per second are better.
A baseline of raw math is included when relevant.
If you want a different library to be added to the benchmark, make an issue or create a pull request if you're comfortable.
Convert 24 hours to minutes
Library
Median execution time
75th percentile execution time
Executions per second
math (baseline)
50
ns (100%)
50
ns (100%)
20,000,000
/sec
simple-units (fast)
140
ns (280%)
150
ns (300%)
7,142,857
/sec
convert (fast)
150
ns (300%)
151
ns (302%)
6,666,667
/sec
uom (fast)
231
ns (462%)
241
ns (482%)
4,329,004
/sec
moment (popular)
470
ns (940%)
481
ns (962%)
2,127,660
/sec
safe-units (fast)
491
ns (982%)
510
ns (1,020%)
2,036,660
/sec
dayjs (popular)
591
ns (1,182%)
611
ns (1,222%)
1,692,047
/sec
luxon (popular)
1,082
ns (2,164%)
1,102
ns (2,204%)
924,214
/sec
js-quantities (popular)
2,165
ns (4,330%)
2,205
ns (4,410%)
461,894
/sec
convert-units (popular)
34,623
ns (69,246%)
34,751
ns (69,502%)
28,883
/sec
Convert 8192 bytes to the best applicable unit
Library
Median execution time
75th percentile execution time
Executions per second
convert (fast)
731
ns (100%)
781
ns (107%)
1,367,989
/sec
byte-size (popular)
28,799
ns (3,940%)
29,615
ns (4,051%)
34,723
/sec
convert-units (popular)
75,391
ns (10,313%)
75,967
ns (10,392%)
13,264
/sec
Convert 4 inches to millimeters
Library
Median execution time
75th percentile execution time
Executions per second
math (baseline)
60
ns (100%)
70
ns (117%)
16,666,667
/sec
simple-units (fast)
140
ns (233%)
141
ns (235%)
7,142,857
/sec
convert (fast)
150
ns (250%)
160
ns (267%)
6,666,667
/sec
uom (fast)
240
ns (400%)
250
ns (417%)
4,166,667
/sec
safe-units (fast)
491
ns (818%)
492
ns (820%)
2,036,660
/sec
js-quantities (popular)
2,185
ns (3,642%)
2,205
ns (3,675%)
457,666
/sec
convert-units (popular)
17,727
ns (29,545%)
17,775
ns (29,625%)
56,411
/sec
Convert 2.5 liters to cubic inches
Library
Median execution time
75th percentile execution time
Executions per second
math (baseline)
50
ns (100%)
50
ns (100%)
20,000,000
/sec
simple-units (fast)
131
ns (262%)
140
ns (280%)
7,633,588
/sec
convert (fast)
140
ns (280%)
151
ns (302%)
7,142,857
/sec
uom (fast)
511
ns (1,022%)
531
ns (1,062%)
1,956,947
/sec
safe-units (fast)
1,192
ns (2,384%)
1,203
ns (2,406%)
838,926
/sec
js-quantities (popular)
3,067
ns (6,134%)
3,105
ns (6,210%)
326,052
/sec
convert-units (popular)
38,015
ns (76,030%)
38,175
ns (76,350%)
26,305
/sec
Parse "10h" and convert it to milliseconds
Library
Median execution time
75th percentile execution time
Executions per second
ms (popular)
190
ns (100%)
191
ns (101%)
5,263,158
/sec
@lukeed/ms (fast)
250
ns (132%)
251
ns (132%)
4,000,000
/sec
convert (fast)
280
ns (147%)
281
ns (148%)
3,571,429
/sec
Convert 24 hours to minutes, but with bigint
s
Library
Median execution time
75th percentile execution time
Executions per second
math (baseline)
50
ns (100%)
50
ns (100%)
20,000,000
/sec
convert (fast)
100
ns (200%)
101
ns (202%)
10,000,000
/sec