-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Decreased performance compared to the original distance_of_time_in_words #79
Comments
@Brotakuu could you provide your benchmark? # clone the repo.
# gem install rails benchmark-ips
# add this file to the root folder of the repo.
$: << File.join(`pwd`.chomp, "lib")
require 'active_support/all'
require 'action_view'
require 'benchmark/ips'
require 'dotiw'
include ActionView::Helpers::DateHelper
Benchmark.ips do |bm|
bm.report("distance_of_time_in_words") { distance_of_time_in_words(Time.now, Time.now + 100.years + 30.days + 50.seconds) }
bm.report("old_distance_of_time_in_words") { old_distance_of_time_in_words(Time.now, Time.now + 100.years + 30.days + 50.seconds) }
bm.compare!
end These are the results I got:
|
I've noticed that it'd include the time spent calculating: Time.now + the dates math of the arguments. This is more accurate, for this case: # clone the repo.
# gem install rails benchmark-ips
# add this file to the root folder of the repo.
$: << File.join(`pwd`.chomp, "lib")
require 'active_support/all'
require 'action_view'
require 'benchmark/ips'
require 'dotiw'
include ActionView::Helpers::DateHelper
Benchmark.ips do |bm|
now = Time.now
future_time = Time.now + 100.years + 30.days + 50.seconds
bm.report("distance_of_time_in_words") { distance_of_time_in_words(now,future_time) }
bm.report("old_distance_of_time_in_words") { old_distance_of_time_in_words(now, future_time, include_seconds: true) }
bm.compare!
end
Observations:
|
dblock
changed the title
Performance running slow
Decreased performance compared to the original distance_of_time_in_words
Jul 2, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great gem, but the performance seems to be significantly slower than the method it replaces. Running a benchmark 10000 times, it is on average 4x slower.
Any idea how to speed it up?
The text was updated successfully, but these errors were encountered: