-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathbenchmark.rb
More file actions
executable file
·32 lines (25 loc) · 829 Bytes
/
benchmark.rb
File metadata and controls
executable file
·32 lines (25 loc) · 829 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/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)