Skip to content

Some benchmarks of community-made JavaScript libraries for converting units.

Notifications You must be signed in to change notification settings

jonahsnider/js-unit-conversion-benchmarks

Repository files navigation

JavaScript unit conversion benchmarks

Some benchmarks of community-made JavaScript/TypeScript libraries for converting units.

Results

Generated automatically at Sat, 01 Jun 2024 21:48:00 GMT with Node.js v18.20.3 (V8 v10.2.154.26-node.37) on fv-az1240-545 (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) 110ns (100%) 130ns (118%) 9,090,909/sec
convert (fast) 321ns (292%) 351ns (319%) 3,115,265/sec
simple-units (fast) 471ns (428%) 521ns (474%) 2,123,142/sec
uom (fast) 561ns (510%) 612ns (556%) 1,782,531/sec
moment (popular) 1,093ns (994%) 1,162ns (1,056%) 914,913/sec
safe-units (fast) 1,302ns (1,184%) 1,422ns (1,293%) 768,049/sec
dayjs (popular) 1,422ns (1,293%) 1,512ns (1,375%) 703,235/sec
luxon (popular) 2,655ns (2,414%) 2,785ns (2,532%) 376,648/sec
js-quantities (popular) 4,631ns (4,210%) 4,811ns (4,374%) 215,936/sec
convert-units (popular) 72,191ns (65,628%) 73,215ns (66,559%) 13,852/sec

Convert 8192 bytes to the best applicable unit

Library Median execution time 75th percentile execution time Executions per second
convert (fast) 822ns (100%) 1,122ns (136%) 1,216,545/sec
byte-size (popular) 35,039ns (4,263%) 51,167ns (6,225%) 28,540/sec
convert-units (popular) 85,567ns (10,410%) 156,159ns (18,997%) 11,687/sec

Convert 4 inches to millimeters

Library Median execution time 75th percentile execution time Executions per second
math (baseline) 141ns (100%) 160ns (113%) 7,092,199/sec
convert (fast) 301ns (213%) 370ns (262%) 3,322,259/sec
simple-units (fast) 431ns (306%) 561ns (398%) 2,320,186/sec
uom (fast) 531ns (377%) 691ns (490%) 1,883,239/sec
safe-units (fast) 1,293ns (917%) 1,784ns (1,265%) 773,395/sec
js-quantities (popular) 4,479ns (3,177%) 5,823ns (4,130%) 223,264/sec
convert-units (popular) 37,023ns (26,257%) 38,815ns (27,528%) 27,010/sec

Convert 2.5 liters to cubic inches

Library Median execution time 75th percentile execution time Executions per second
math (baseline) 121ns (100%) 140ns (116%) 8,264,463/sec
convert (fast) 371ns (307%) 401ns (331%) 2,695,418/sec
simple-units (fast) 501ns (414%) 561ns (464%) 1,996,008/sec
uom (fast) 1,403ns (1,160%) 1,523ns (1,259%) 712,758/sec
safe-units (fast) 1,744ns (1,441%) 1,933ns (1,598%) 573,394/sec
js-quantities (popular) 6,835ns (5,649%) 7,347ns (6,072%) 146,306/sec
convert-units (popular) 80,831ns (66,802%) 81,471ns (67,331%) 12,371/sec

Parse "10h" and convert it to milliseconds

Library Median execution time 75th percentile execution time Executions per second
@lukeed/ms (fast) 491ns (100%) 541ns (110%) 2,036,660/sec
ms (popular) 521ns (106%) 572ns (116%) 1,919,386/sec
convert (fast) 601ns (122%) 662ns (135%) 1,663,894/sec

Convert 24 hours to minutes, but with bigints

Library Median execution time 75th percentile execution time Executions per second
math (baseline) 211ns (100%) 230ns (109%) 4,739,336/sec
convert (fast) 531ns (252%) 581ns (275%) 1,883,239/sec

About

Some benchmarks of community-made JavaScript libraries for converting units.

Topics

Resources

Stars

Watchers

Forks