Simple Machines Blogs > Developers' Blog
PHP String Replacement Speed Comparison
KGIII:
Would you like tests from multiple servers perhaps or just one result per person will be enough for an informal test such as this?
ディン1031:
On my small Private Windows Test Server
Processor: Intel Core2Duo 6600 @ 2.40GHz
RAM: 2048 MB
Operating System: Microsoft Windows XP [Version 5.1.2600]
Current processes: 47 (47 running, 0 zombie)
PHP version: 5.1.4
Server version: Apache/2.2.2 (Win32) DAV/2 mod_ssl/2.2.2 OpenSSL/0.9.8b mod_autoindex_color PHP/5.1.4
--- Code: ---sprintf: 0.73141002655 seconds
preg_replace: 1.26732420921 seconds
strtr: 23.7995750904 seconds
str_replace #1: 0.864935159683 seconds
str_replace #2: 1.10788106918 seconds
--- End code ---
(Or should i test it on my other server with linux on it :x).
Bye
DIN1031
Saleh:
OS: Windows XP Media Center SP2
CPU: Intel CentrinoDuo T7200 @ 2.00GHz
RAM: 1 GB @ 2.00 GHz
Server: Apache 1.3.34 w/ PHP5 mod
PHP: 5.2.2
Results:
sprintf: 0.80260682106018 seconds
preg_replace: 2.3465528488159 seconds
strtr: 26.90654706955 seconds
str_replace #1: 0.83384084701538 seconds
str_replace #2: 1.1157829761505 seconds
although running this test on windows is kinda useless but meh
anyhow, PHP uses only 1 processor and leaves the other so I was running 50% CPU all the time.
Results from my webhosting account:
Operating system: FreeBSD
Kernel version: 6.1-RELEASE-p4
Machine Type: amd64
Apache version: 1.3.37 (Unix)
PHP version 4.4.2 (outdated!?)
RUN 1:
Server Load: 1.03 (2 cpus)
Memory Used: 67.77 %
sprintf: 1.22852993011 seconds
preg_replace: 2.19928884506 seconds
strtr: 41.4552869797 seconds
str_replace #1: 1.34867596626 seconds
str_replace #2: 1.66192102432 seconds
RUN 2:
Server Load 0.88 (2 cpus)
Memory Used 62.88 %
sprintf: 1.16300082207 seconds
preg_replace: 1.57117605209 seconds
strtr: 34.872027874 seconds
str_replace #1: 1.37249684334 seconds
str_replace #2: 1.51887798309 seconds
RUN 3:
Server Load 1.50 (2 cpus)
Memory Used 65.80 %
sprintf: 1.24492406845 seconds
preg_replace: 1.72587108612 seconds
strtr: 36.0469529629 seconds
str_replace #1: 1.16329097748 seconds
str_replace #2: 1.65367412567 seconds
Note all those server status were taken the moment the benchmark started
SleePy:
--- Quote ---sprintf: 1.5811309814453 seconds
preg_replace: 2.1888408660889 seconds
strtr: 45.443498849869 seconds
str_replace #1: 2.333279132843 seconds
str_replace #2: 2.0846509933472 seconds
--- End quote ---
Kinda high because I was running a php script already before that that does take up some processes.
For anyone with max_execution_time error add this to the top of the file just after the <?php
--- Code: ---set_time_limit(120);
--- End code ---
Daniel15:
And here's mine from my web hosting server:
--- Quote ---daniel15@blue [~/tmp]# ./benchmark.php
sprintf: 0.950059890747 seconds
preg_replace: 1.63948893547 seconds
strtr: 38.4129178524 seconds
str_replace #1: 0.748620033264 seconds
str_replace #2: 0.989835977554 seconds
--- End quote ---
System information:
--- Quote ---
daniel15@blue [~/tmp]# uname -a
Linux blue.inviohosting.com 2.6.9-55.EL #1 Wed May 2 13:52:16 EDT 2007 i686 athlon i386 GNU/Linux
daniel15@blue [~/tmp]# php -v
PHP 5.2.2 with Suhosin-Patch 0.9.6.2 (cli) (built: May 11 2007 23:54:15)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
with XCache v1.2.0, Copyright (c) 2005-2006, by mOo
daniel15@blue [~/tmp]# uptime
01:02:57 up 24 days, 15:04, 1 user, load average: 0.04, 0.10, 0.15
daniel15@blue [~/tmp]# cat /proc/cpuinfo
processor : 0
vendor_id : AuthenticAMD
cpu family : 15
model : 47
model name : AMD Athlon(tm) 64 Processor 3800+
stepping : 2
cpu MHz : 2389.466
cache size : 512 KB
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 1
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 pni syscall nx mmxext fxsr_opt lm 3dnowext 3dnow pni
bogomips : 4780.45
--- Code: ---daniel15@blue [~/tmp]# ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 2460 452 ? S May18 0:01 init [3]
root 2 0.0 0.0 0 0 ? SN May18 0:00 [ksoftirqd/0]
root 3 0.0 0.0 0 0 ? S< May18 0:00 [events/0]
root 4 0.0 0.0 0 0 ? S< May18 0:00 [khelper]
root 5 0.0 0.0 0 0 ? S< May18 0:00 [kacpid]
root 29 0.0 0.0 0 0 ? S< May18 0:00 [kblockd/0]
root 30 0.0 0.0 0 0 ? S May18 0:00 [khubd]
root 49 0.0 0.0 0 0 ? S May18 0:31 [kswapd0]
root 50 0.0 0.0 0 0 ? S< May18 0:00 [aio/0]
root 194 0.0 0.0 0 0 ? S May18 0:00 [kseriod]
root 418 0.0 0.0 0 0 ? S< May18 0:00 [ata/0]
root 419 0.0 0.0 0 0 ? S< May18 0:00 [ata_aux]
root 421 0.0 0.0 0 0 ? S May18 0:00 [scsi_eh_0]
root 422 0.0 0.0 0 0 ? S May18 0:00 [scsi_eh_1]
root 434 0.0 0.0 0 0 ? S May18 5:27 [kjournald]
root 1578 0.0 0.3 10376 3488 ? S May18 1:29 lfd - sleeping
root 1698 0.0 0.0 3176 356 ? S<s May18 0:00 udevd
root 1881 0.0 0.0 0 0 ? S< May18 0:00 [kedac]
root 2025 0.0 0.0 0 0 ? S< May18 0:00 [kauditd]
root 2088 0.0 0.0 0 0 ? S May18 0:00 [kjournald]
root 2734 0.0 0.0 2556 516 ? Ss May18 1:24 syslogd -m 0
root 2738 0.0 0.0 2260 376 ? Ss May18 0:01 klogd -x
named 2760 0.0 0.2 39232 2692 ? Ssl May18 1:35 /usr/sbin/named -u named
root 2834 0.0 0.0 4232 200 ? Ss May18 0:00 rpc.idmapd
root 2995 0.0 0.0 4256 164 ? Ss May18 0:00 /var/dcc/libexec/dccifd -tCMN,5, -llog -wwhiteclnt -Uuserdirs -SHELO -Smail_host -SSender -SLi
root 2996 0.0 0.1 47112 1500 ? Sl May18 0:03 /var/dcc/libexec/dccifd -tCMN,5, -llog -wwhiteclnt -Uuserdirs -SHELO -Smail_host -SSender -SLi
root 3007 0.0 0.0 3152 436 ? S May18 0:00 /usr/sbin/smartd
root 3016 0.0 0.0 2620 360 ? Ss May18 0:00 /usr/sbin/acpid
root 3039 0.0 0.0 2320 516 ? Ss May18 0:00 xinetd -stayalive -pidfile /var/run/xinetd.pid
root 4144 0.0 0.0 7316 696 ? Ss May18 0:00 pure-ftpd (SERVER)
root 4148 0.0 0.0 6916 592 ? S May18 0:00 /usr/sbin/pure-authd -s /var/run/ftpd.sock -r /usr/sbin/pureauth
root 4289 0.0 0.1 5168 1064 ? S May18 0:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/blue.inviohost
mysql 4318 0.1 6.0 208000 58800 ? Sl May18 70:01 /usr/sbin/mysqld --basedir=/ --datadir=/var/lib/mysql --user=mysql --pid-file=/var/lib/mysql/b
root 4350 0.0 0.2 9792 2396 ? Ss May18 0:04 /usr/sbin/munin-node
xfs 4470 0.0 0.0 3700 616 ? Ss May18 0:00 xfs -droppriv -daemon
dbus 4727 0.0 0.0 2524 300 ? Ss May18 0:00 dbus-daemon-1 --system
root 4737 0.0 0.1 7012 1412 ? Ss May18 0:01 hald
root 4759 0.0 0.0 1488 336 ? Ss May18 0:00 /usr/sbin/portsentry -tcp
root 4939 0.0 0.0 0 0 ? S< May18 0:21 [loop0]
root 4940 0.0 0.0 0 0 ? S May18 0:01 [kjournald]
root 4947 0.0 0.0 2052 328 tty1 Ss+ May18 0:00 /sbin/mingetty tty1
root 4948 0.0 0.0 1564 328 tty2 Ss+ May18 0:00 /sbin/mingetty tty2
root 4949 0.0 0.0 2776 328 tty3 Ss+ May18 0:00 /sbin/mingetty tty3
root 4950 0.0 0.0 2392 328 tty4 Ss+ May18 0:00 /sbin/mingetty tty4
root 4951 0.0 0.0 2700 328 tty5 Ss+ May18 0:00 /sbin/mingetty tty5
root 4952 0.0 0.0 2988 328 tty6 Ss+ May18 0:00 /sbin/mingetty tty6
root 5394 0.0 0.0 1524 384 ? S Jun10 0:00 /usr/sbin/courierlogger -pid=/var/run/imapd.pid -start -name=imapd /usr/lib/courier-imap/libex
root 5395 0.0 0.0 2108 472 ? S Jun10 0:00 /usr/lib/courier-imap/libexec/couriertcpd -address=0 -maxprocs=40 -maxperip=30 -nodnslookup -n
root 5401 0.0 0.0 2252 236 ? S Jun10 0:00 /usr/sbin/courierlogger -pid=/var/run/imapd-ssl.pid -start -name=imapd-ssl /usr/lib/courier-im
root 5402 0.0 0.0 1704 400 ? S Jun10 0:00 /usr/lib/courier-imap/libexec/couriertcpd -address=0 -maxprocs=40 -maxperip=30 -nodnslookup -n
root 5407 0.0 0.0 2500 384 ? S Jun10 0:00 /usr/sbin/courierlogger -pid=/var/run/pop3d.pid -start -name=pop3d /usr/lib/courier-imap/libex
root 5408 0.0 0.0 3088 472 ? S Jun10 0:00 /usr/lib/courier-imap/libexec/couriertcpd -address=0 -maxprocs=40 -maxperip=30 -nodnslookup -n
root 5413 0.0 0.0 3340 236 ? S Jun10 0:00 /usr/sbin/courierlogger -pid=/var/run/pop3d-ssl.pid -start -name=pop3d-ssl /usr/lib/courier-im
root 5414 0.0 0.0 2504 400 ? S Jun10 0:00 /usr/lib/courier-imap/libexec/couriertcpd -address=0 -maxprocs=40 -maxperip=30 -nodnslookup -n
root 5419 0.0 0.0 2956 320 ? S Jun10 0:00 /usr/sbin/courierlogger -pid=/var/spool/authdaemon/pid -facility=mail -start /usr/libexec/cour
root 5420 0.0 0.0 3136 488 ? S Jun10 0:00 /usr/libexec/courier-authlib/authdaemond
root 5424 0.0 0.0 3136 308 ? S Jun10 0:00 /usr/libexec/courier-authlib/authdaemond
root 5425 0.0 0.0 3136 308 ? S Jun10 0:00 /usr/libexec/courier-authlib/authdaemond
root 5426 0.0 0.0 3136 312 ? S Jun10 0:00 /usr/libexec/courier-authlib/authdaemond
root 5427 0.0 0.0 3136 308 ? S Jun10 0:00 /usr/libexec/courier-authlib/authdaemond
root 5428 0.0 0.0 3136 264 ? S Jun10 0:00 /usr/libexec/courier-authlib/authdaemond
root 6517 0.0 0.0 4760 908 ? Ss May19 0:00 crond
root 7475 0.0 0.2 6444 2032 ? S Jun10 0:00 cpbandwd
root 10276 0.0 0.1 8668 1712 ? S Jun10 0:00 /usr/bin/perl /usr/local/cpanel/bin/leechprotect
nobody 10277 0.1 1.6 41608 16264 ? S Jun10 2:06 /usr/local/apache/bin/httpd
nobody 10278 0.1 2.0 51820 19976 ? S Jun10 2:03 /usr/local/apache/bin/httpd
nobody 10279 0.1 1.7 63640 16816 ? S Jun10 2:01 /usr/local/apache/bin/httpd
nobody 10280 0.1 2.5 52272 25040 ? S Jun10 2:07 /usr/local/apache/bin/httpd
nobody 10281 0.1 1.7 54600 16736 ? S Jun10 2:00 /usr/local/apache/bin/httpd
nobody 10285 0.1 1.7 58620 17072 ? S Jun10 2:11 /usr/local/apache/bin/httpd
nobody 10300 0.1 1.6 53608 16060 ? S Jun10 1:53 /usr/local/apache/bin/httpd
nobody 10303 0.1 1.7 39252 16800 ? S Jun10 2:01 /usr/local/apache/bin/httpd
nobody 10304 0.1 1.7 42124 16616 ? S Jun10 2:12 /usr/local/apache/bin/httpd
nobody 10306 0.1 1.9 50428 18424 ? S Jun10 2:15 /usr/local/apache/bin/httpd
root 10576 0.0 0.6 12748 6352 ? SN Jun10 0:30 cpanellogd - sleeping for logs
mailnull 10589 0.0 0.2 7264 2096 ? S Jun10 0:00 eximstats
mailman 10597 0.0 0.0 11984 948 ? Ss Jun10 0:00 /usr/local/bin/python2.4 /usr/local/cpanel/3rdparty/mailman/bin/mailmanctl -s start
mailman 10608 0.0 0.3 12120 2936 ? S Jun10 0:00 /usr/local/bin/python2.4 /usr/local/cpanel/3rdparty/mailman/bin/qrunner --runner=ArchRunner:0:
mailman 10609 0.0 0.3 10564 2968 ? S Jun10 0:00 /usr/local/bin/python2.4 /usr/local/cpanel/3rdparty/mailman/bin/qrunner --runner=BounceRunner:
mailman 10610 0.0 0.3 10660 2940 ? S Jun10 0:00 /usr/local/bin/python2.4 /usr/local/cpanel/3rdparty/mailman/bin/qrunner --runner=CommandRunner
mailman 10611 0.0 0.3 10740 2984 ? S Jun10 0:00 /usr/local/bin/python2.4 /usr/local/cpanel/3rdparty/mailman/bin/qrunner --runner=IncomingRunne
mailman 10612 0.0 0.3 10192 2948 ? S Jun10 0:00 /usr/local/bin/python2.4 /usr/local/cpanel/3rdparty/mailman/bin/qrunner --runner=NewsRunner:0:
mailman 10613 0.0 0.3 10768 3116 ? S Jun10 0:00 /usr/local/bin/python2.4 /usr/local/cpanel/3rdparty/mailman/bin/qrunner --runner=OutgoingRunne
mailman 10614 0.0 0.3 11460 3012 ? S Jun10 0:00 /usr/local/bin/python2.4 /usr/local/cpanel/3rdparty/mailman/bin/qrunner --runner=VirginRunner:
mailman 10615 0.0 0.3 10272 2956 ? S Jun10 0:00 /usr/local/bin/python2.4 /usr/local/cpanel/3rdparty/mailman/bin/qrunner --runner=RetryRunner:0
nobody 10640 0.0 0.0 5716 584 ? S Jun10 0:00 entropychat
root 10645 0.0 0.0 14556 268 ? S Jun10 0:00 cpdavd - accepting connections on 2077 and 2078
root 12454 0.0 0.1 5296 1860 ? S Jun10 0:01 /etc/authlib/authProg
root 12469 0.0 0.1 5296 1900 ? S Jun10 0:00 /etc/authlib/authProg
root 13154 0.0 0.1 5296 1888 ? S Jun10 0:00 /etc/authlib/authProg
root 15969 0.0 0.0 0 0 ? S Jun11 0:00 [pdflush]
root 21223 0.0 0.1 5296 1924 ? S Jun10 0:01 /etc/authlib/authProg
root 21955 0.0 1.0 23904 10080 ? Ss Jun10 0:01 /usr/local/apache/bin/httpd
root 23158 0.0 0.0 0 0 ? S May26 0:07 [pdflush]
root 24093 0.0 0.5 9088 4956 ? S Jun11 0:00 chkservd
root 26135 0.8 2.7 31232 26300 ? Ss 00:33 0:16 /usr/sbin/clamd
mailnull 26141 0.0 0.0 9200 908 ? Ss 00:33 0:00 /usr/sbin/exim -bd -q60m
mailnull 26146 0.0 0.0 8768 852 ? Ss 00:33 0:00 /usr/sbin/exim -tls-on-connect -bd -oX 465
root 26152 0.0 0.1 4120 1140 ? S 00:33 0:00 antirelayd
root 26168 0.0 4.1 43404 39948 ? Ss 00:33 0:01 /usr/bin/spamd -d --allowed-ips=127.0.0.1 --pidfile=/var/run/spamd.pid --max-children=5
root 26172 0.0 4.1 43812 40084 ? S 00:33 0:00 spamd child
root 26173 0.0 3.9 43404 38324 ? S 00:33 0:00 spamd child
32029 26827 0.0 0.1 4048 1432 ? S 00:41 0:00 /usr/lib/courier-imap/bin/imapd /home/dansoft/mail
daniel15 26828 0.0 0.1 4776 1052 ? S 00:41 0:00 /usr/lib/courier-imap/bin/imapd /home/daniel15/mail
32004 26829 0.0 0.0 3708 764 ? S 00:41 0:00 /usr/lib/courier-imap/bin/imapd /home/invio/mail/inviohosting.com/daniel
root 26993 0.0 1.0 20320 9932 ? S Jun11 0:00 cpsrvd - waiting for connections
root 27871 0.0 0.2 7964 2244 ? Ss 00:56 0:00 sshd: daniel15 [priv]
daniel15 27873 0.0 0.1 8108 1720 ? S 00:56 0:00 sshd: daniel15@pts/1
root 27874 0.0 0.0 1520 552 ? Ss 00:56 0:00 -jailshell
daniel15 27885 0.0 0.1 2968 1312 ? S 00:56 0:00 -jailshell
nobody 28358 0.0 0.9 24036 9468 ? S 01:04 0:00 /usr/local/apache/bin/httpd
daniel15 28683 0.0 0.0 2960 788 ? R+ 01:05 0:00 ps aux
root 31622 0.0 0.2 5296 2008 ? S Jun11 0:00 /etc/authlib/authProg
root 32657 0.0 0.0 5736 772 ? Ss May26 0:00 /usr/sbin/sshd
--- End code ---
("ps" output in code box because it's long :P)
--- End quote ---
I love using a relatively small web host - The load average is awesome. I actually do maintenance work for the host (InVio Hosting) :D
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version