-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconst_get_bench.rb
55 lines (41 loc) · 943 Bytes
/
const_get_bench.rb
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# frozen_string_literal: true
require_relative '../../lib/ruby-on-speed'
RubyOnSpeed.benchmark 'Ruby:const_get - get a constant value' do
module ConstGet
CONST = 'value'
class << self
attr_reader :const_attr
def const = 'value'
end
@const_attr = 'value'
module Indirect
def self.const = CONST
def self.const_call = ConstGet.const
def self.const_attr = ConstGet.const_attr
end
end
code '::CONST' do
ConstGet::CONST
end
code '.const_get(Symbol)' do
ConstGet.const_get(:CONST)
end
code '.const_get(String)' do
ConstGet.const_get('CONST')
end
code '.const' do
ConstGet.const
end
code '.const_attr' do
ConstGet.const_attr
end
code 'Indirect.const' do
ConstGet::Indirect.const
end
code 'Indirect.const_call' do
ConstGet::Indirect.const_call
end
code 'Indirect.const_attr' do
ConstGet::Indirect.const_attr
end
end