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 Wed, 11 Dec 2024 15:54:51 GMT with Node.js v22.11.0 (V8 v12.4.254.21-node.21) on fv-az1040-926 (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) 50ns (100%) 50ns (100%) 20,000,000/sec
simple-units (fast) 100ns (200%) 101ns (202%) 10,000,000/sec
convert (fast) 110ns (220%) 110ns (220%) 9,090,909/sec
convert-units (popular) 110ns (220%) 110ns (220%) 9,090,909/sec
uom (fast) 230ns (460%) 240ns (480%) 4,347,826/sec
moment (popular) 381ns (762%) 381ns (762%) 2,624,672/sec
safe-units (fast) 451ns (902%) 461ns (922%) 2,217,295/sec
dayjs (popular) 541ns (1,082%) 561ns (1,122%) 1,848,429/sec
luxon (popular) 1,042ns (2,084%) 1,052ns (2,104%) 959,693/sec
js-quantities (popular) 1,994ns (3,988%) 2,014ns (4,028%) 501,505/sec

Convert 8192 bytes to the best applicable unit

Library Median execution time 75th percentile execution time Executions per second
convert (fast) 601ns (100%) 681ns (113%) 1,663,894/sec
convert-units (popular) 1,102ns (183%) 1,193ns (199%) 907,441/sec
byte-size (popular) 26,655ns (4,435%) 28,351ns (4,717%) 37,516/sec

Convert 4 inches to millimeters

Library Median execution time 75th percentile execution time Executions per second
math (baseline) 70ns (100%) 70ns (100%) 14,285,714/sec
convert-units (popular) 110ns (157%) 111ns (159%) 9,090,909/sec
convert (fast) 111ns (159%) 121ns (173%) 9,009,009/sec
simple-units (fast) 120ns (171%) 120ns (171%) 8,333,333/sec
uom (fast) 210ns (300%) 221ns (316%) 4,761,905/sec
safe-units (fast) 441ns (630%) 450ns (643%) 2,267,574/sec
js-quantities (popular) 2,085ns (2,979%) 2,105ns (3,007%) 479,616/sec

Convert 2.5 liters to cubic inches

Library Median execution time 75th percentile execution time Executions per second
math (baseline) 50ns (100%) 50ns (100%) 20,000,000/sec
simple-units (fast) 110ns (220%) 120ns (240%) 9,090,909/sec
convert-units (popular) 121ns (242%) 130ns (260%) 8,264,463/sec
convert (fast) 130ns (260%) 130ns (260%) 7,692,308/sec
uom (fast) 501ns (1,002%) 511ns (1,022%) 1,996,008/sec
safe-units (fast) 1,132ns (2,264%) 1,142ns (2,284%) 883,392/sec
js-quantities (popular) 2,895ns (5,790%) 2,917ns (5,834%) 345,423/sec

Parse "10h" and convert it to milliseconds

Library Median execution time 75th percentile execution time Executions per second
ms (popular) 200ns (100%) 200ns (100%) 5,000,000/sec
@lukeed/ms (fast) 230ns (115%) 231ns (116%) 4,347,826/sec
convert (fast) 270ns (135%) 271ns (136%) 3,703,704/sec

Convert 24 hours to minutes, but with bigints

Library Median execution time 75th percentile execution time Executions per second
math (baseline) 50ns (100%) 50ns (100%) 20,000,000/sec
convert (fast) 100ns (200%) 100ns (200%) 10,000,000/sec

About

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

Topics

Resources

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •