mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Add vm_ivar get, get_unitialized, and lazy_set benchmarks
This commit is contained in:
parent
f98d6d3f38
commit
513a11b477
Notes:
git
2022-09-15 05:51:10 +09:00
3 changed files with 61 additions and 0 deletions
37
benchmark/vm_ivar_get.yml
Normal file
37
benchmark/vm_ivar_get.yml
Normal file
|
@ -0,0 +1,37 @@
|
|||
prelude: |
|
||||
class Example
|
||||
def initialize
|
||||
@v0 = 1
|
||||
@v1 = 2
|
||||
@v3 = 3
|
||||
@levar = 1
|
||||
end
|
||||
|
||||
def get_value_loop
|
||||
sum = 0
|
||||
|
||||
i = 0
|
||||
while i < 1000000
|
||||
# 10 times to de-emphasize loop overhead
|
||||
sum += @levar
|
||||
sum += @levar
|
||||
sum += @levar
|
||||
sum += @levar
|
||||
sum += @levar
|
||||
sum += @levar
|
||||
sum += @levar
|
||||
sum += @levar
|
||||
sum += @levar
|
||||
sum += @levar
|
||||
i += 1
|
||||
end
|
||||
|
||||
return sum
|
||||
end
|
||||
end
|
||||
|
||||
obj = Example.new
|
||||
benchmark:
|
||||
vm_ivar_get: |
|
||||
obj.get_value_loop
|
||||
loop_count: 100
|
12
benchmark/vm_ivar_get_unintialized.yml
Normal file
12
benchmark/vm_ivar_get_unintialized.yml
Normal file
|
@ -0,0 +1,12 @@
|
|||
prelude: |
|
||||
class Example
|
||||
def read
|
||||
@uninitialized
|
||||
end
|
||||
end
|
||||
|
||||
obj = Example.new
|
||||
benchmark:
|
||||
vm_ivar_get_uninitialized: |
|
||||
obj.read
|
||||
loop_count: 30000000
|
12
benchmark/vm_ivar_lazy_set.yml
Normal file
12
benchmark/vm_ivar_lazy_set.yml
Normal file
|
@ -0,0 +1,12 @@
|
|||
prelude: |
|
||||
class Example
|
||||
def lazy_set
|
||||
@uninitialized ||= 123
|
||||
end
|
||||
end
|
||||
|
||||
objs = 10000000.times.map { Example.new }
|
||||
benchmark:
|
||||
vm_ivar_lazy_set: |
|
||||
objs.each(&:lazy_set)
|
||||
loop_count: 1
|
Loading…
Add table
Reference in a new issue