forked from zerohistory/toystore
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A few scripts I've been playing with to test performance of various t…
…hings.
- Loading branch information
1 parent
617fd06
commit fad9e2f
Showing
2 changed files
with
78 additions
and
0 deletions.
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,45 @@ | ||
# require 'perftools' | ||
require 'pp' | ||
require 'logger' | ||
require 'benchmark' | ||
require 'rubygems' | ||
|
||
$:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib') | ||
require 'toystore' | ||
require 'adapter/memory' | ||
|
||
Toy.logger = ::Logger.new(STDOUT).tap { |log| log.level = ::Logger::INFO } | ||
|
||
class User | ||
include Toy::Store | ||
identity_map_off | ||
store(:memory, {}) | ||
attribute :name, String | ||
end | ||
|
||
user = User.create(:name => 'John') | ||
id = user.id | ||
times = 10_000 | ||
|
||
client_result = Benchmark.realtime { | ||
times.times { User.store.decode(User.store.client[User.store.key_for(id)]) } | ||
} | ||
|
||
store_result = Benchmark.realtime { | ||
times.times { User.get(id) } | ||
} | ||
|
||
puts 'Client', client_result | ||
puts 'Toystore', store_result | ||
puts 'Ratio', store_result / client_result | ||
|
||
# PerfTools::CpuProfiler.start('prof_client') do | ||
# times.times{ User.store.decode(User.store.client[User.store.key_for(id)]) } | ||
# end | ||
|
||
# PerfTools::CpuProfiler.start('prof_reads') do | ||
# times.times{ User.get(id) } | ||
# end | ||
|
||
# system('pprof.rb --gif --ignore=Collection#find_one prof_reads > prof_reads.gif') | ||
# system('open prof_reads.gif') |
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,33 @@ | ||
# require 'perftools' | ||
require 'pp' | ||
require 'logger' | ||
require 'benchmark' | ||
require 'rubygems' | ||
|
||
$:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib') | ||
require 'toystore' | ||
require 'adapter/memory' | ||
|
||
Toy.logger = ::Logger.new(STDOUT).tap { |log| log.level = ::Logger::INFO } | ||
|
||
class User | ||
include Toy::Store | ||
identity_map_off | ||
store(:memory, {}) | ||
end | ||
|
||
times = 10_000 | ||
user = User.new | ||
id = user.id | ||
attrs = user.persisted_attributes | ||
|
||
client_result = Benchmark.realtime { | ||
times.times { User.store.write(id, attrs) } | ||
} | ||
store_result = Benchmark.realtime { | ||
times.times { User.create } | ||
} | ||
|
||
puts 'Client', client_result | ||
puts 'Toystore', store_result | ||
puts 'Ratio', store_result / client_result |