Skip to content
Time constants, in seconds, so you don't have to use slow ActiveSupport helpers
Ruby
Latest commit 2ab9160 Mar 21, 2011 Evan Weaver Static code generation.
Failed to load latest commit information.
lib Static code generation. Mar 21, 2011
test/unit First commit. Feb 25, 2011
CHANGELOG Static code generation. Mar 22, 2011
LICENSE First commit. Feb 25, 2011
Manifest Manifest Feb 25, 2011
README Benchmarks. Feb 25, 2011
Rakefile Static code generation. Mar 22, 2011

README

TimeConstants

Time constants, in seconds, so you don't have to use slow ActiveSupport helpers.

== Usage

  require 'time_constants'

You get toplevel constants from 0 to 100, except for days, which goes to 500.

  T_1_SECOND
  T_2_SECONDS

  T_1_MINUTE
  T_2_MINUTES

  T_1_HOUR
  T_2_HOURS

  T_1_DAY
  T_2_DAYS

  T_1_WEEK
  T_2_WEEKS

  T_1_MONTH
  T_2_MONTHS

  T_1_YEAR
  T_2_YEARS

  T_1_SOLAR_YEAR
  T_2_SOLAR_YEARS

Note that you do not need to refer to <tt>Time::</tt>.

== Benchmark

  require 'time_constants'
  require 'active_support'

  def benchmark(times = 100000, samples = 20)
    times *= samples
    cur = Time.now
    result = times.times { yield }
    print "#{cur = (Time.now - cur) / samples.to_f } seconds"
    puts " (#{(cur / $last_benchmark * 100).to_i - 100}% change)" rescue puts ""
    $last_benchmark = cur
    result
  end

  > benchmark { T_6_MONTHS }
  0.03336355 seconds
  > benchmark { 6.months.to_i }
  1.65868245 seconds (4871% change)

== License

Copyright 2011 Twitter, Inc. Licensed under the Apache 2 license. See the included LICENSE file.
Something went wrong with that request. Please try again.