Sha256: c78e3afbbc9805fde7df92ab67970126ce756fd8570728d31b217580fd602d40

Contents?: true

Size: 1.1 KB

Versions: 13

Compression:

Stored size: 1.1 KB

Contents

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

require 'benchmark'
require 'timezone'

def load_tz(timezone)
  Timezone.fetch(timezone)
end

puts 'Loading timezones'

LOAD_ITERATIONS = 1_000
Benchmark.bm do |x|
  x.report('la') { LOAD_ITERATIONS.times { load_tz('America/Los_Angeles') } }
  x.report('hk') { LOAD_ITERATIONS.times { load_tz('Asia/Hong_Kong') } }
end

def calc_local(timezone)
  timezone.time(Time.utc(3000, 1, 1))
end

puts 'Calculating LOCAL'

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

def calc_utc(timezone)
  timezone.local_to_utc(Time.utc(3000, 1, 1))
end

puts 'Calculating UTC'

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

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
timezone-1.3.8 benchmark.rb
timezone-1.3.7 benchmark.rb
timezone-1.3.6 benchmark.rb
timezone-1.3.5 benchmark.rb
timezone-1.3.4 benchmark.rb
timezone-1.3.3 benchmark.rb
timezone-1.3.2 benchmark.rb
timezone-1.3.1 benchmark.rb
timezone-1.3.0 benchmark.rb
timezone-1.2.12 benchmark.rb
timezone-1.2.11 benchmark.rb
timezone-1.2.10 benchmark.rb
timezone-1.2.9 benchmark.rb