Sha256: 3144a3d98e168fe3fed4f65a64aa276124f82227f8e6d231004377e086e35690

Contents?: true

Size: 829 Bytes

Versions: 20

Compression:

Stored size: 829 Bytes

Contents

#!/usr/bin/env ruby
# frozen_string_literal: true

require 'benchmark'
require 'timezone'

puts 'Loading timezones'

Benchmark.bm do |x|
  x.report('la') { 10_000.times { Timezone.fetch('America/Los_Angeles') } }
  x.report('hk') { 10_000.times { Timezone.fetch('Asia/Hong_Kong') } }
end

def calc(method, timezone, time)
  timezone.public_send(method, time)
end

def bench(iterations, method)
  Benchmark.bm do |x|
    time = Time.utc(3000, 1, 1)
    timezone = Timezone.fetch('America/Los_Angeles')
    x.report('la') { iterations.times { calc(method, timezone, time) } }
    timezone = Timezone.fetch('Asia/Hong_Kong')
    x.report('hk') { iterations.times { calc(method, timezone, time) } }
  end
end

puts 'Calculating LOCAL (#time)'
bench(10_000, :time)

puts 'Calculating UTC (#local_to_utc)'
bench(10_000, :local_to_utc)

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
timezone-1.3.28 benchmark.rb
timezone-1.3.27 benchmark.rb
timezone-1.3.26 benchmark.rb
timezone-1.3.25 benchmark.rb
timezone-1.3.24 benchmark.rb
timezone-1.3.23 benchmark.rb
timezone-1.3.22 benchmark.rb
timezone-1.3.21 benchmark.rb
timezone-1.3.20 benchmark.rb
timezone-1.3.19 benchmark.rb
timezone-1.3.18 benchmark.rb
timezone-1.3.17 benchmark.rb
timezone-1.3.16 benchmark.rb
timezone-1.3.15 benchmark.rb
timezone-1.3.14 benchmark.rb
timezone-1.3.13 benchmark.rb
timezone-1.3.12 benchmark.rb
timezone-1.3.11 benchmark.rb
timezone-1.3.10 benchmark.rb
timezone-1.3.9 benchmark.rb