-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Define Fluent::EventTime#inspect method #1915
Conversation
okkez
commented
Mar 29, 2018
•
edited
Loading
edited
The 3rd argument of |
Oh, thanks! I will check this tomorrow. |
Because 3 arguments version of `Time.at` has been added since Ruby 2.5.0. See also https://bugs.ruby-lang.org/issues/13919
I've checked |
lib/fluent/time.rb
Outdated
@@ -108,6 +108,10 @@ def self.parse(*args) | |||
def method_missing(name, *args, &block) | |||
@sec.send(name, *args, &block) | |||
end | |||
|
|||
def inspect | |||
Time.at(self).strftime('%Y-%m-%d %H:%M:%S.%N %z') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about using Strftime
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the suggestion!
Strftime is faster than Time#strftime. ``` $ bundle exec ruby t.rb Rehearsal ------------------------------------------------- Time#strftime 4.380378 0.835296 5.215674 ( 5.219284) Strftime 2.861623 0.740209 3.601832 ( 3.603956) ---------------------------------------- total: 8.817506sec user system total real Time#strftime 4.688617 0.847361 5.535978 ( 5.539647) Strftime 2.691129 0.852342 3.543471 ( 3.546031) ``` Using following benchmark script: ```ruby require "benchmark" require_relative "./lib/fluent/load" N = 1000 formatter = Strftime.new('%Y-%m-%d %H:%M:%S.%N %z') event_times = [] 1000.times do event_times << Fluent::EventTime.new(Time.now.to_i, (rand * 10**9).to_i) end Benchmark.bmbm do |x| x.report("Time#strftime") do N.times do event_times.each do |event_time| Time.at(event_time).strftime('%Y-%m-%d %H:%M:%S.%N %z') end end end x.report("Strftime") do N.times do event_times.each do |event_time| formatter.exec(Time.at(event_time)) end end end end ```
Thanks! |