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