Posts Tagged ‘microseconds’

fwrite vs fputs in php

Monday, July 14th, 2008

So far all the functions have been running fast anyway so the difference haven’t been that significant but things are starting to get interesting with the run time jumping to 20-24 microseconds to write a short string to a file.

fwrite vs fputs
fwrite: 24.9826359749 seconds
fputs: 20.1990799904 seconds
Time saved: 4.7835559845 seconds; 23.6820488199%

With a difference of over 4 microseconds you could run both fputs and floatval in the time it takes to run fwrite. The difference is over 23% which clearly makes fputs the better function. It’s shorter as well.

chop vs rtrim in php

Monday, July 14th, 2008

Tidying up a string breaks the pattern. Maybe my analysis was a little premature.

chop vs rtrim
chop: 4.73731994629 seconds
rtrim: 4.41647195816 seconds
Time saved: 0.320847988129 seconds; 7.26480301852%

rtrim is a little faster and these functions take longer at a little over 4 microseconds.

Php:is_int vs is_integer

Monday, July 14th, 2008

Next it is time to try some validation with is_int and is_integer.

is_int vs is_integer
is_int: 3.11394786835 seconds
is_integer: 3.42630600929 seconds
Time saved: 0.312358140945 seconds; 9.11646946006%

The difference is smaller this time but again both functions are executing in a little over 3 microseconds. is_int is faster than is_integer so again the shorter function name wins. Is this going to be a pattern?