Skip to content

Instantly share code, notes, and snippets.

@php-cpm
Created July 24, 2018 09:37
Show Gist options
  • Save php-cpm/dc5bc659ecb7732ccc890d852b5ee56e to your computer and use it in GitHub Desktop.
Save php-cpm/dc5bc659ecb7732ccc890d852b5ee56e to your computer and use it in GitHub Desktop.
<?php
// refer & edit from https://odino.org/redis-slow-with-php-think-again/
$conn = mysqli_connect('127.0.0.1', 'root');
mysqli_select_db($conn, 'mysql_benchmark');
for ($i = 0; $i < 100; $i++) {
$start = microtime(true);
for ($j = 0; $j < 10000; $j++) {
$query = mysqli_query($conn, 'SELECT * FROM users WHERE id = 1');
$key = sprintf("key:%05d", $j);
$persone = mysqli_fetch_row($query);
}
$time = microtime(true)-$start;
printf("%6d req/sec\n", $j/$time);
}
@php-cpm
Copy link
Author

php-cpm commented Jul 30, 2018

sudo dtruss -c php mysql.php

CALL                                        COUNT
bsdthread_register                              1
connect                                         1
fchmod                                          1
ftruncate                                       1
getentropy                                      1
getpid                                          1
getrlimit                                       1
getuid                                          1
shm_open                                        1
sigprocmask                                     1
thread_selfid                                   1
csops                                           2
fstatat64                                       2
fstatfs64                                       2
getegid                                         2
gettid                                          2
issetugid                                       2
openat_nocancel                                 2
socket                                          2
unlink                                          2
access                                          3
geteuid                                         3
getdirentries64                                 4
sysctl                                          4
fcntl_nocancel                                  5
madvise                                         6
pread                                          12
open                                           13
close                                          15
fcntl                                          16
lstat64                                        17
mprotect                                       17
readlink                                       18
read_nocancel                                  19
munmap                                         35
lseek                                          41
sigaction                                      45
close_nocancel                                 48
open_nocancel                                  50
stat64                                         56
fstat64                                        58
ioctl                                          73
mmap                                           75
getattrlist                                   132
sendto                                       1556
recvfrom                                     3233
poll                                         3234

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment