Skip to content
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

Merged
merged 3 commits into from
Apr 2, 2018

Commits on Mar 29, 2018

  1. Define Fluent::EventTime#inspect method

        time = Fluent::EventTime.now
        # previous version
        p time # => #<Fluent::EventTime:0x00005635d50ecdb8 @sec=1522311320, @nsec=861617325>
        # this version
        p time # => 2018-03-29 17:15:20.861617325 +0900
    okkez committed Mar 29, 2018
    Configuration menu
    Copy the full SHA
    f90b9e6 View commit details
    Browse the repository at this point in the history

Commits on Mar 30, 2018

  1. Use Time.at(self) instead of Time.at(@sec, @nsec, :nanoseconds)

    Because 3 arguments version of `Time.at` has been added since Ruby 2.5.0.
    See also https://bugs.ruby-lang.org/issues/13919
    okkez committed Mar 30, 2018
    Configuration menu
    Copy the full SHA
    456d356 View commit details
    Browse the repository at this point in the history
  2. Use Strftime instead of Time#strftime

    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
    ```
    okkez committed Mar 30, 2018
    Configuration menu
    Copy the full SHA
    9db478b View commit details
    Browse the repository at this point in the history