Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- mysql_connect('localhost','root','EDITED');
- mysql_select_db('test');
- mysql_query('truncate test');
- start();
- for ($x=0; $x<100; $x++) {
- mysql_query('insert into test (test) values ('.$x.')');
- }
- stop('dumb insert',100);
- $array = [];
- for ($x=0; $x<100; $x++) {
- $array[] = '('.$x.')';
- }
- $query = 'insert into test(test) values '.implode($array,',');
- start();
- for ($x=0; $x<100; $x++) {
- mysql_query($query);
- }
- stop('dumb + bulk',100*100);
- start();
- mysql_query('begin');
- for ($x=0; $x<2000; $x++) {
- mysql_query('insert into test (test) values ('.$x.')');
- }
- mysql_query('commit');
- stop('dumb insert with transaction',2000);
- start();
- mysql_query('begin');
- for ($x=0; $x<100; $x++) {
- mysql_query($query);
- }
- mysql_query('commit');
- stop('bulk with transaction',100*100);
- function start() {
- global $st;
- $st = microtime(true);
- }
- function stop($name,$rows) {
- global $st;
- echo $name.': '.($rows/(microtime(true) - $st))." rows/sec\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement