Advertisement
Guest User

Untitled

a guest
Apr 14th, 2013
424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. <?php
  2. mysql_connect('localhost','root','EDITED');
  3. mysql_select_db('test');
  4. mysql_query('truncate test');
  5. start();
  6. for ($x=0; $x<100; $x++) {
  7. mysql_query('insert into test (test) values ('.$x.')');
  8. }
  9. stop('dumb insert',100);
  10.  
  11. $array = [];
  12. for ($x=0; $x<100; $x++) {
  13. $array[] = '('.$x.')';
  14. }
  15. $query = 'insert into test(test) values '.implode($array,',');
  16. start();
  17. for ($x=0; $x<100; $x++) {
  18. mysql_query($query);
  19. }
  20. stop('dumb + bulk',100*100);
  21.  
  22. start();
  23. mysql_query('begin');
  24. for ($x=0; $x<2000; $x++) {
  25. mysql_query('insert into test (test) values ('.$x.')');
  26. }
  27. mysql_query('commit');
  28. stop('dumb insert with transaction',2000);
  29.  
  30. start();
  31. mysql_query('begin');
  32. for ($x=0; $x<100; $x++) {
  33. mysql_query($query);
  34. }
  35. mysql_query('commit');
  36. stop('bulk with transaction',100*100);
  37.  
  38. function start() {
  39. global $st;
  40. $st = microtime(true);
  41. }
  42. function stop($name,$rows) {
  43. global $st;
  44. echo $name.': '.($rows/(microtime(true) - $st))." rows/sec\n";
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement