Last active
May 14, 2016 07:36
-
-
Save kunitoo/065ea8c4fd5c827e0773e16f7961ec47 to your computer and use it in GitHub Desktop.
neo4jrb bulk create benchmark | neo4j (7.0.6) neo4j-core (6.1.4) neo4j-rake_tasks (0.5.4)
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 'neo4j' | |
require 'benchmark' | |
Neo4j::Session.open(:server_db) | |
class Post | |
include Neo4j::ActiveNode | |
id_property :number | |
end | |
def delete_all | |
Neo4j::Session.current._query('MATCH (n) DETACH DELETE n') | |
end | |
delete_all | |
Benchmark.bm 15 do |r| | |
batch_size = 1000 | |
delete_all | |
r.report 'normal create' do | |
batch_size.times do |i| | |
Post.create(number: i) | |
end | |
end | |
r.report 'bulk create' do | |
queries = [] | |
batch_size.times do |i| | |
queries << "(:Post{number: #{i + batch_size}})" | |
end | |
Neo4j::Session.current._query('create ' + queries.join(',')) | |
end | |
end | |
# $ ruby benchmark.rb | |
# user system total real | |
# normal create 3.220000 0.170000 3.390000 ( 25.560404) | |
# bulk create 0.010000 0.000000 0.010000 ( 0.162243) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment