Skip to content

Instantly share code, notes, and snippets.

@mackee
Created May 30, 2013 05:33
Show Gist options
  • Save mackee/5675879 to your computer and use it in GitHub Desktop.
Save mackee/5675879 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use Benchmark qw/cmpthese/;
use Test::mysqld;
use DBI;
use Sys::Ramdisk;
use feature qw/say/;
my $mysqld =
Test::mysqld->new(
my_cnf => {
'skip-networking' => '',
},
);
my $dbh = DBI->connect($mysqld->dsn(dbname => 'test'));
my $ramdisk = Sys::Ramdisk->new(size => '100m');
$ramdisk->mount();
my $mysqld_inmemory =
Test::mysqld->new(
my_cnf => {
'skip-networking' => '',
datadir => $ramdisk->dir(),
}
);
my $dbh_inmemory = DBI->connect($mysqld_inmemory->dsn(dbname => 'test'));
my $create_sql = <<"SQL";
CREATE TABLE IF NOT EXISTS `sample_table` (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
PRIMARY KEY (`id`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
SQL
my $drop_sql = <<"SQL";
DROP TABLE `sample_table`;
SQL
cmpthese(0, {
'basic' => sub {
$dbh->do($create_sql);
$dbh->do($drop_sql);
},
'inmemory' => sub {
$dbh_inmemory->do($create_sql);
$dbh_inmemory->do($drop_sql);
},
});
END {
$ramdisk->unmount();
}
__DATA__
$ perl benchmark_ddl.pl
Rate basic inmemory
basic 5585/s -- -58%
inmemory 13292/s 138% --
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment