Skip to content

Instantly share code, notes, and snippets.

@yasuoza
Created October 11, 2012 15:10
Show Gist options
  • Save yasuoza/3873106 to your computer and use it in GitHub Desktop.
Save yasuoza/3873106 to your computer and use it in GitHub Desktop.
Benchmark for mroonga
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
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"';
@yasuoza
Copy link
Author

yasuoza commented Oct 11, 2012

Result

      user     system      total        real
   0.180000   0.090000   0.270000 ( 45.093617) # default column
   0.050000   0.030000   0.080000 (  1.081635) # MySQL index
   0.040000   0.030000   0.070000 (  1.024571) # mroonga

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