-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add benchmarks and a few slight optimizations
- Loading branch information
brainopia
committed
Oct 16, 2010
1 parent
8c5ab26
commit 9ae139b
Showing
4 changed files
with
70 additions
and
4 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
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,46 @@ | ||
require 'bundler' | ||
Bundler.require :benchmark | ||
|
||
$:.unshift './../lib' | ||
require 'cell' | ||
require 'map' | ||
require 'worm' | ||
require 'human' | ||
require 'benchmark' | ||
|
||
def json(command, data) | ||
JSON.generate [command, data] | ||
end | ||
|
||
Benchmark.bmbm do |x| | ||
x.report('Worm.new') do | ||
1000.times do | ||
json('id', Object.new.object_id) | ||
Worm.new Object.new | ||
end | ||
end | ||
|
||
x.report('Worm.find+direction') do | ||
1000.times do | ||
socket = Object.new | ||
Worm.new socket | ||
Worm.find(socket).direction = '1'.to_i | ||
end | ||
end | ||
|
||
x.report('Periodic Timer') do | ||
10.times do | ||
Worm.all.each &:move | ||
json = JSON.generate ['render', Map.data] | ||
Worm.sockets.map do | ||
json | ||
end | ||
end | ||
end | ||
|
||
x.report('Worm.destroy') do | ||
1000.times do | ||
Worm.destroy Worm.storage.first.first | ||
end | ||
end | ||
end |
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