Created
March 9, 2011 16:11
-
-
Save shageman/862470 to your computer and use it in GitHub Desktop.
Performance comparison MySQL and Neo4j
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 'activesupport', '~>2.3.4', :require => 'active_support' | |
gem 'i18n' | |
group :test do | |
gem 'test-unit', :require => 'test/unit' | |
gem 'minitest' | |
gem 'dm-core' | |
gem 'dm-mysql-adapter' | |
gem 'dm-migrations' | |
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
require "rubygems" | |
require 'bundler' | |
Bundler.require(:default, :test) | |
require 'active_support/test_case' | |
require 'minitest/autorun' | |
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 | |
end | |
def setup | |
DataMapper.setup(:default, 'mysql://localhost/perf_test') | |
DataMapper.finalize | |
DataMapper.auto_migrate! | |
end | |
def test_mysql_insertions | |
Benchmark.bm do |b| | |
[1,10,100,1000,10000].each do |num| | |
b.report "Creating #{num} users (MySQL with DataMapper)\n" do | |
num.times do |i| | |
User.create(:name => "User#{i}") | |
end | |
end | |
end | |
end | |
end | |
def test_neo_insertions_without_indexing | |
Benchmark.bm do |b| | |
[1,10,100,1000,10000].each do |num| | |
b.report "Creating #{num} users (Neo4j without index)\n" do | |
num.times do |i| | |
NeoUser.create_without_index({ :obj_id => i, :name => "User#{i}", :obj_class => "NeoUser" }) | |
end | |
end | |
end | |
end | |
end | |
def test_neo_insertions | |
Benchmark.bm do |b| | |
[1,10,100,1000,10000].each do |num| | |
b.report "Creating #{num} users (Neo4j with index)\n" do | |
num.times do |i| | |
NeoUser.create({ :obj_id => i, :name => "User#{i}", :obj_class => "NeoUser" }) | |
end | |
end | |
end | |
end | |
end | |
def test_neo_find_or_create | |
Benchmark.bm do |b| | |
[1,10,100,1000,10000].each do |num| | |
b.report "Finding or creating #{num} users (Neo4j with index)\n" do | |
num.times do |i| | |
NeoUser.find_or_create({ :obj_id => i, :name => "User#{i}", :obj_class => "NeoUser" }) | |
end | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My results: