Skip to content

Instantly share code, notes, and snippets.

@shageman
Created March 9, 2011 16:11
Show Gist options
  • Save shageman/862470 to your computer and use it in GitHub Desktop.
Save shageman/862470 to your computer and use it in GitHub Desktop.
Performance comparison MySQL and Neo4j
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
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
@shageman
Copy link
Author

shageman commented Mar 9, 2011

My results:

          user     system      total        real
    Creating 1 users (MySQL with DataMapper)
      0.000000   0.000000   0.000000 (  0.001342)
    Creating 10 users (MySQL with DataMapper)
      0.000000   0.000000   0.000000 (  0.009371)
    Creating 100 users (MySQL with DataMapper)
      0.040000   0.000000   0.040000 (  0.442795)
    Creating 1000 users (MySQL with DataMapper)
      0.360000   0.050000   0.410000 (  1.205662)
    Creating 10000 users (MySQL with DataMapper)
      3.720000   0.520000   4.240000 ( 20.966412)

          user     system      total        real
    Finding or creating 1 users (Neo4j with index)
      0.000000   0.000000   0.000000 (  0.062627)
    Finding or creating 10 users (Neo4j with index)
      0.050000   0.010000   0.060000 (  0.245700)
    Finding or creating 100 users (Neo4j with index)
      0.500000   0.060000   0.560000 (  3.298020)
    Finding or creating 1000 users (Neo4j with index)
      4.990000   0.600000   5.590000 ( 30.672252)
    Finding or creating 10000 users (Neo4j with index)
     50.520000   5.940000  56.460000 (350.368157)

          user     system      total        real
    Creating 1 users (Neo4j with index)
      0.010000   0.000000   0.010000 (  0.096335)
    Creating 10 users (Neo4j with index)
      0.030000   0.000000   0.030000 (  0.303664)
    Creating 100 users (Neo4j with index)
      0.410000   0.040000   0.450000 (  3.057566)
    Creating 1000 users (Neo4j with index)
      4.080000   0.430000   4.510000 ( 31.277669)
    Creating 10000 users (Neo4j with index)
     39.880000   4.090000  43.970000 (282.022798)

          user     system      total        real
    Creating 1 users (Neo4j without index)
      0.000000   0.000000   0.000000 (  0.004032)
    Creating 10 users (Neo4j without index)
      0.020000   0.000000   0.020000 (  0.112236)
    Creating 100 users (Neo4j without index)
      0.170000   0.020000   0.190000 (  0.433538)
    Creating 1000 users (Neo4j without index)
      1.870000   0.190000   2.060000 (  4.791801)
    Creating 10000 users (Neo4j without index)
     18.610000   1.950000  20.560000 ( 49.025879)


    Finished in 778.588388 seconds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment