TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-09-2008, 11:34 PM   #1 (permalink)
The Addict
 
Join Date: Nov 2007
Posts: 264
Thanks: 2
TlcAndres is on a distinguished road
Default 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.
TlcAndres is offline  
Reply With Quote
The Following User Says Thank You to TlcAndres For This Useful Post:
Wildhoney (01-10-2008)
Old 01-09-2008, 11:35 PM   #2 (permalink)
The Addict
 
webtuto's Avatar
 
Join Date: Dec 2007
Location: morocco
Posts: 221
Thanks: 19
webtuto is on a distinguished road
Default

thanks dude
Send a message via MSN to webtuto Send a message via Yahoo to webtuto Send a message via Skype™ to webtuto
webtuto is offline  
Reply With Quote
Old 01-10-2008, 01:50 AM   #3 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

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.
Salathe is offline  
Reply With Quote
Old 01-10-2008, 02:02 AM   #4 (permalink)
The Addict
 
Join Date: Nov 2007
Posts: 264
Thanks: 2
TlcAndres is on a distinguished road
Default

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.
TlcAndres is offline  
Reply With Quote
Old 01-10-2008, 12:54 PM   #5 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
Alan @ CIT is on a distinguished road
Default

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
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 07:05 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design