Created
March 17, 2011 04:54
-
-
Save riywo/873865 to your computer and use it in GitHub Desktop.
DBD::mysqlでのinsertの処理時間(localhost接続)
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
mysql> select * from microsec limit 10; | |
+------------+--------+ | |
| epoch | us | | |
+------------+--------+ | |
| 1300337288 | 938208 | | |
| 1300337288 | 965069 | | |
| 1300337288 | 976498 | | |
| 1300337288 | 987483 | | |
| 1300337288 | 998476 | | |
| 1300337289 | 9421 | | |
| 1300337289 | 20474 | | |
| 1300337289 | 31551 | | |
| 1300337289 | 42421 | | |
| 1300337289 | 53417 | | |
+------------+--------+ |
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
auto_commit = 0 | |
$ perl microsec.pl| awk '{sum+=$1}END{print sum/NR}' | |
11.9695 | |
$ perl microsec.pl| awk '{sum+=$1}END{print sum/NR}' | |
11.1182 | |
$ perl microsec.pl| awk '{sum+=$1}END{print sum/NR}' | |
11.0386 | |
$ perl microsec.pl| awk '{sum+=$1}END{print sum/NR}' | |
11.9484 | |
$ perl microsec.pl| awk '{sum+=$1}END{print sum/NR}' | |
11.7235 | |
auto_commit = 1 | |
$ perl microsec.pl| awk '{sum+=$1}END{print sum/NR}' | |
11.0103 | |
$ perl microsec.pl| awk '{sum+=$1}END{print sum/NR}' | |
11.2025 | |
$ perl microsec.pl| awk '{sum+=$1}END{print sum/NR}' | |
11.7875 | |
$ perl microsec.pl| awk '{sum+=$1}END{print sum/NR}' | |
11.3994 | |
$ perl microsec.pl| awk '{sum+=$1}END{print sum/NR}' | |
11.0079 |
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
use strict; | |
use warnings; | |
use DBI; | |
use Time::HiRes qw(gettimeofday usleep); | |
my $user = 'root'; | |
my $pass = ''; | |
my $db = 'test'; | |
my $table = 'microsec'; | |
my $auto_commit = 0; | |
#my $auto_commit = 1; | |
my $DDL = <<SQL; | |
create table `$table` ( | |
`epoch` int unsigned not null, | |
`us` int unsigned not null | |
) | |
SQL | |
my $dbh = DBI->connect("dbi:mysql:database=$db;", $user, $pass, | |
{ RaiseError => 1, AutoCommit => $auto_commit }); | |
$dbh->do("drop table if exists `$table`"); | |
$dbh->do($DDL); | |
$dbh->commit if($auto_commit == 0); | |
my $sth = $dbh->prepare("insert into `$table` values (?, ?)"); | |
my ($epoch, $us); | |
for (1..300) { | |
($epoch, $us) = gettimeofday; | |
$sth->execute($epoch, $us); | |
$dbh->commit if($auto_commit == 0); | |
usleep 10000; # 10ms | |
} | |
my $ref = $dbh->selectall_arrayref("select `us` from `$table`"); | |
for (my $i=1; $i<=$#{$ref}; $i++ ) { | |
my $ms_diff = ($ref->[$i][0] - $ref->[$i-1][0]); | |
$ms_diff += $ms_diff < 0 ? 1000000 : 0; | |
print $ms_diff/1000 ."\n"; | |
} | |
$dbh->disconnect; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
約1ms強かかっている印象。usleepを8500くらいにすれば丁度10msくらいの感覚になりそう。
auto_commitの有無はほとんど影響なさそう。