aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/bin
diff options
context:
space:
mode:
authorschneems <richard.schneeman+foo@gmail.com>2018-08-29 11:36:07 -0500
committerschneems <richard.schneeman+foo@gmail.com>2018-08-29 11:45:47 -0500
commite81b0ddd7ac9fe6de0ec65a2aa59224108344470 (patch)
tree93748ed6b8141db8f939c0e3c3fb5d967ad938f4 /activemodel/bin
parent96d7504da9273e8fcd18823173537678f4cf2321 (diff)
downloadrails-e81b0ddd7ac9fe6de0ec65a2aa59224108344470.tar.gz
rails-e81b0ddd7ac9fe6de0ec65a2aa59224108344470.tar.bz2
rails-e81b0ddd7ac9fe6de0ec65a2aa59224108344470.zip
Faster time_value.rb
The multiplication of the value takes a long time when we can instead mutate and use the string value directly. The `microsec` perf increases speed by 27% in the ideal case (which is the most common). ``` original_string = ".443959" require 'benchmark/ips' Benchmark.ips do |x| x.report("multiply") { string = original_string.dup (string.to_r * 1_000_000).to_i } x.report("new ") { string = original_string.dup if string && string.start_with?(".".freeze) && string.length == 7 string[0] = ''.freeze string.to_i end } x.compare! end # Warming up -------------------------------------- # multiply 125.783k i/100ms # new 146.543k i/100ms # Calculating ------------------------------------- # multiply 1.751M (± 3.3%) i/s - 8.805M in 5.033779s # new 2.225M (± 2.1%) i/s - 11.137M in 5.007110s # Comparison: # new : 2225289.7 i/s # multiply: 1751254.2 i/s - 1.27x slower ```
Diffstat (limited to 'activemodel/bin')
0 files changed, 0 insertions, 0 deletions