Created
March 10, 2011 11:17
-
-
Save drexin/863959 to your computer and use it in GitHub Desktop.
Performance comparison find by id
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
require "rubygems" | |
require 'bundler' | |
Bundler.require(:default, :test) | |
require 'active_support/test_case' | |
require 'benchmark' | |
class LinearityTest < ActiveSupport::TestCase | |
def self.neo | |
@@neo ||= Neography::Rest.new() | |
end | |
class User | |
include DataMapper::Resource | |
property :id, Serial | |
property :name, String | |
end | |
class NeoUser | |
def self.create(params) | |
@neo_node = Neography::Node.create(LinearityTest.neo, params) | |
LinearityTest.neo.add_node_to_index(params[:obj_class], 'obj_id', @neo_node.obj_id, @neo_node.neo_id) | |
end | |
def self.create_without_index(params) | |
Neography::Node.create(LinearityTest.neo, params) | |
end | |
def self.find_or_create(params) | |
LinearityTest.neo.get_node_index(params[:obj_class], 'obj_id', params[:node_id]) || create(params) | |
end | |
def self.find(id) | |
nodes = LinearityTest.neo.get_node_index("NeoUser", 'obj_id', id) | |
user = Neography::Node.new(nodes.first) | |
user | |
end | |
end | |
def setup | |
DataMapper.setup(:default, 'mysql://localhost/perf_test') | |
DataMapper.finalize | |
DataMapper.auto_migrate! | |
end | |
test "performance of find_by_id (MySQL)" do | |
[1,10,100,1000,10000].each do |num| | |
num.times do |i| | |
begin | |
User.create({ :id => i, :name => "User#{i}"}) | |
rescue | |
end | |
end | |
Benchmark.bm do |b| | |
b.report "Finding #{num} users by id (MySQL)\n" do | |
num.times do |i| | |
User.find(i) | |
end | |
end | |
end | |
end | |
end | |
test "performance of find_by_id (Neo4j)" do | |
[1,10,100,1000,10000].each do |num| | |
num.times do |i| | |
NeoUser.create({ :obj_id => i, :name => "User#{i}", :obj_class => "NeoUser" }) | |
end | |
Benchmark.bm do |b| | |
b.report "Finding #{num} users by id (Neo4j)\n" do | |
num.times do |i| | |
NeoUser.find(i) | |
end | |
end | |
end | |
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
source "http://rubygems.org" | |
gem 'neography' | |
gem 'test-unit', :require => 'test/unit' | |
gem 'dm-core' | |
gem 'dm-mysql-adapter' | |
gem 'dm-migrations' |
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
#MySQL | |
user system total real | |
Finding 1 users by id (MySQL) | |
0.000000 0.000000 0.000000 ( 0.000011) | |
user system total real | |
Finding 10 users by id (MySQL) | |
0.000000 0.000000 0.000000 ( 0.000016) | |
user system total real | |
Finding 100 users by id (MySQL) | |
0.000000 0.000000 0.000000 ( 0.000059) | |
user system total real | |
Finding 1000 users by id (MySQL) | |
0.000000 0.000000 0.000000 ( 0.000441) | |
user system total real | |
Finding 10000 users by id (MySQL) | |
0.000000 0.000000 0.000000 ( 0.004126) | |
user system total real | |
# Neo4j | |
Finding 1 users by id (Neo4j) | |
0.040000 0.000000 0.040000 ( 0.068566) | |
user system total real | |
Finding 10 users by id (Neo4j) | |
0.230000 0.000000 0.230000 ( 0.356628) | |
user system total real | |
Finding 100 users by id (Neo4j) | |
1.160000 0.020000 1.180000 ( 1.731973) | |
user system total real | |
Finding 1000 users by id (Neo4j) | |
6.040000 0.230000 6.270000 ( 10.127834) | |
user system total real | |
Finding 10000 users by id (Neo4j) | |
32.060000 1.870000 33.930000 ( 53.359652) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment