Last active
September 14, 2019 22:23
-
-
Save hartator/b320c6b521fe7e325c449b4c51f268dc to your computer and use it in GitHub Desktop.
Simple script to benchmark MongoDB using Ruby (Related article: https://medium.com/@hartator/mongodb-4-2-vs-4-0-3-6-3-4-and-3-2-benchmarks-ee96a09ef231)
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 'mongo' | |
require 'digest' | |
require 'benchmark' | |
Mongo::Logger.logger.level = Logger::WARN | |
client = Mongo::Client.new('mongodb://127.0.0.1:27017/test') | |
sleep 1 | |
puts "Insert" | |
puts Benchmark.measure { | |
100_000.times do |index| | |
client[:users].insert_one(name: Digest::MD5.hexdigest(index.to_s)) | |
end | |
} | |
puts | |
sleep 1 | |
puts "Read" | |
puts Benchmark.measure { | |
100.times do | |
client[:users].find({}).to_a | |
end | |
} | |
puts | |
sleep 1 | |
puts "Delete" | |
puts Benchmark.measure { | |
client[:users].delete_many({}) | |
} | |
puts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment