Skip to content

Instantly share code, notes, and snippets.

@deekayen
Created May 14, 2014 04:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deekayen/7e2816a39279d95605a1 to your computer and use it in GitHub Desktop.
Save deekayen/7e2816a39279d95605a1 to your computer and use it in GitHub Desktop.
A timer script I wrote to find out how long it would take to do a command-line import of a SQL file. Used to test the difference in import times between the Antelope and Barracuda XtraDB storage formats. Barracuda turned out a 3% speed gain.
#!/usr/bin/php
<?php
$db = array();
$db['host'] = 'localhost';
$db['user'] = 'root';
$db['password'] = '';
$db['database'] = 'barracuda';
// END configuration
class Timer {
protected $last, $timers = array(), $length = 10;
public function start() {
$this->last = microtime(TRUE);
}
public function mark($name) {
$this->timers[$name] = microtime(TRUE) - $this->last;
$this->last = microtime(TRUE);
$this->length = max(strlen($name) + 2, $this->length);
}
public function display() {
foreach ($this->timers as $name => $value) printf("%-{$this->length}s: %.3f secs" . PHP_EOL, $name, $value);
}
}
if (empty($argv[1])) {
echo 'No input SQL filename provided.';
die(1);
}
$timer = new Timer;
$timer->start();
shell_exec("mysql -u {$db['user']} -p{$db['password']} {$db['database']} < {$argv[1]}");
$timer->mark('InnoDB import');
shell_exec("mysql --secure-auth -u {$db['user']} -h {$db['host']} -p{$db['password']} -BN {$db['database']} -e \"SHOW TABLES\" | awk '{print \"DROP TABLE \" $1 \";\"}' | mysql --secure-auth -u {$db['user']} -h {$db['host']} -p{$db['password']} {$db['database']}");
$timer->mark('Drop tables');
$timer->display();
die(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment