This repository has been archived by the owner on Nov 30, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 394
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve
change
mather detection of objects that have changed. (#1132)
* Add instance variables to changes detected * Add benchmark for large objects
- Loading branch information
Showing
3 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
require 'benchmark/ips' | ||
|
||
OBJECT_VARIABLES = Object.instance_method(:instance_variables) | ||
OBJECT_VARIABLE_GET = Object.instance_method(:instance_variable_get) | ||
|
||
def calculate_attribute_hashes(object) | ||
OBJECT_VARIABLES.bind(object).call.map { |name| OBJECT_VARIABLE_GET.bind(object).call(name).hash } | ||
end | ||
|
||
[10, 100, 1000, 10000].each do |object_size| | ||
klass = Class.new do | ||
define_method(:initialize) do | ||
object_size.times do |i| | ||
instance_variable_set(:"@my_var_#{i}", 'a' * (rand * 100)) | ||
end | ||
end | ||
end | ||
instance = klass.new | ||
|
||
Benchmark.ips do |ips| | ||
ips.report("Get hashes for object of size: #{instance.instance_variables.size}") do | ||
calculate_attribute_hashes(instance) | ||
end | ||
end | ||
end | ||
|
||
# Warming up -------------------------------------- | ||
# Get hashes for object of size: 10 | ||
# 14.412k i/100ms | ||
# Calculating ------------------------------------- | ||
# Get hashes for object of size: 10 | ||
# 158.585k (± 5.2%) i/s - 792.660k in 5.012663s | ||
# Warming up -------------------------------------- | ||
# Get hashes for object of size: 100 | ||
# 1.664k i/100ms | ||
# Calculating ------------------------------------- | ||
# Get hashes for object of size: 100 | ||
# 17.041k (± 9.0%) i/s - 84.864k in 5.036735s | ||
# Warming up -------------------------------------- | ||
# Get hashes for object of size: 1000 | ||
# 173.000 i/100ms | ||
# Calculating ------------------------------------- | ||
# Get hashes for object of size: 1000 | ||
# 1.808k (± 4.6%) i/s - 9.169k in 5.082355s | ||
# Warming up -------------------------------------- | ||
# Get hashes for object of size: 10000 | ||
# 16.000 i/100ms | ||
# Calculating ------------------------------------- | ||
# Get hashes for object of size: 10000 | ||
# 176.298 (± 3.4%) i/s - 896.000 in 5.089070s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters