TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   array_map speed (http://www.talkphp.com/absolute-beginners/1921-array_map-speed.html)

TlcAndres 01-09-2008 11:34 PM

array_map speed
 
Maybe it's just me but I was doing a test and found a normal loop to be faster then array_map (atleast in my case)..here are some of the speed results...

1) looping through an array and using mysql_real_escape_string() on each value

2) using array map with mysql_real_escape_string();

0.000141
0.00068


0.000161
0.000702

0.000351
0.001889

sorry if this has been pointed out before.

webtuto 01-09-2008 11:35 PM

thanks dude

Salathe 01-10-2008 01:50 AM

Hmm interesting. I tried three different approaches (array_map, for, foreach) with the following results.

Code:

Test took 7.684968 seconds to complete
Test array has 100 items
Average of 10,000 iterations, times in 1000ths of a second

array_map => 0.107439
foreach => 0.327824
for => 0.322589

Given those results, which contradict your own, it would appear that array_map is around 3 times faster than for/foreach -- for me at least.

TlcAndres 01-10-2008 02:02 AM

I wonder if anyone else could do a benchmark to see if it's just happen stance. I'm skeptical of my own results since I believed that a built in function would be faster then the aforementioned loop.

Alan @ CIT 01-10-2008 12:54 PM

Here's the results of mine using mysql_real_escape_string on an array with 100 items in it:

Code:

array_map Time Taken: 0.000188
  foreach Time Taken: 0.000850
      for Time Taken: 0.001493
    while Time Taken: 0.001693

Alan


All times are GMT. The time now is 12:19 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0