Created
October 11, 2012 15:10
-
-
Save yasuoza/3873106 to your computer and use it in GitHub Desktop.
Benchmark for mroonga
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 'benchmark' | |
require 'mysql2' | |
DB_NAME = 'bench_mroonga' | |
DB_USERNAME = 'username' | |
DB_USERPASS = 'password' | |
TABLE_NAME = 'benches' | |
insert_cols = ['none', 'mysql', 'mroonga'].join(', ') | |
client = Mysql2::Client.new :host => 'localhost', | |
:database => DB_NAME, | |
:username => DB_USERNAME, | |
:password => DB_USERPASS | |
100000.times do | |
client.query("INSERT INTO #{TABLE_NAME} (#{insert_cols}) \ | |
values (#{Array.new(3, rand(100000)).join(', ')})") | |
end | |
n = 500 | |
QUERY_PREFIX = "select * from #{TABLE_NAME}" | |
Benchmark.bm do |x| | |
x.report { n.times { client.query("#{QUERY_PREFIX} where none like '%#{rand(1000)}%'") } } | |
x.report { n.times { client.query("#{QUERY_PREFIX} where mysql like '#{rand(1000)}%'") } } | |
x.report { n.times { client.query("#{QUERY_PREFIX} where match(mroonga) against(#{rand(1000)})") } } | |
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
CREATE TABLE `benches` ( | |
`id` int(11) NOT NULL AUTO_INCREMENT, | |
`none` varchar(255) DEFAULT NULL, | |
`mysql` varchar(255) DEFAULT NULL, | |
`mroonga` varchar(255) DEFAULT NULL, | |
PRIMARY KEY (`id`), | |
KEY `index_bench_on_mysql` (`mysql`), | |
FULLTEXT KEY `mroonga` (`mroonga`) | |
) ENGINE=mroonga AUTO_INCREMENT=1100159 DEFAULT CHARSET=utf8 COMMENT='engine "innodb"'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Result