[ruby-cvs:70939] naruse:r63848 (trunk): Optimize Time.utc

naruse at ruby-lang.org naruse at ruby-lang.org
Wed Jul 4 19:06:51 JST 2018


naruse	2018-07-04 19:06:51 +0900 (Wed, 04 Jul 2018)

  New Revision: 63848

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63848

  Log:
    Optimize Time.utc
    
    Time.utc uses timegmw() and it uses leap second information.
    If the given time is larger than known_leap_seconds_limit, it calls
    find_time_t, which uses localtime(3) and calls stat(2) in it.
    
    This patch avoid it by setting known_leap_seconds_limit to 0 if the timezone doesn't have leapsecond information (if no leap second is found "now", I assume the timezone doesn't have leapsecond information).
    
    Before:
    % time ./miniruby --disable-gem -e'time = Time.now; year = time.year; month = time.month; day = time.day; hour = time.hour; min = time.min; sec = time.sec + time.subsec; i = 0; while i < 100000; ::Time.utc(year, month, day, hour, min, sec); i += 1; end'
    ./miniruby --disable-gem   0.35s user 0.19s system 99% cpu 0.542 total
    
    After:
    % time ./miniruby --disable-gem -e'time = Time.now; year = time.year; month = time.month; day = time.day; hour = time.hour; min = time.min; sec = time.sec + time.subsec; i = 0; while i < 100000; ::Time.utc(year, month, day, hour, min, sec); i += 1; end'
    ./miniruby --disable-gem   0.23s user 0.00s system 99% cpu 0.233 total

  Modified files:
    trunk/time.c


More information about the ruby-cvs mailing list