Skip to content

Instantly share code, notes, and snippets.

@scottjacobsen
Created August 6, 2021 19:43
Show Gist options
  • Save scottjacobsen/ace4d5d4f47367f9a05aaf2bdc83bf35 to your computer and use it in GitHub Desktop.
Save scottjacobsen/ace4d5d4f47367f9a05aaf2bdc83bf35 to your computer and use it in GitHub Desktop.
to_money.format
[6] pry(main)> Benchmark.ips do |x|
[6] pry(main)* x.report("n2c") { number_to_currency(amount) }
[6] pry(main)* x.report("Money") { amount.to_money.format }
[6] pry(main)* x.compare!
[6] pry(main)* end
Warming up --------------------------------------
n2c 1.024k i/100ms
Money 2.076k i/100ms
Calculating -------------------------------------
n2c 9.718k (± 7.7%) i/s - 49.152k in 5.089582s
Money 18.109k (±16.7%) i/s - 89.268k in 5.108446s
Comparison:
Money: 18108.6 i/s
n2c: 9717.6 i/s - 1.86x (± 0.00) slower
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment