Results 1 to 4 of 4

Thread: Retrieval or Processing which is faster

  1. #1
    Join Date
    Jul 2012
    Posts
    198
    Thanks
    54
    Thanked 3 Times in 3 Posts

    Default Retrieval or Processing which is faster

    i have two choices, i need to know which is faster


    (1)Retrieving the percentage result from database which is already been stored.

    OR

    (2)Adding 10000 different numbers(which includes only numbers 1,2,3) = Total Value

    Multiplying these 10000 x 100 and dividing it to Total Value gives the percentage result ..


    which utilizes the server resources more ?if it is second option why ?
    You will know the truth, and the truth will set you free (John 8:32)(The truth is about the only begotten son of GOD.....When you feel you are alone for facing your problems, God will never leave you by your own You are important for God

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Depends on your server. For example, finding the average of 10,000 numbers between 1 - 3 isn't really lot of work. Likewise, querying a DB is going to take a varying amount of time depending on where it is - could be nearly instantaneous if it's on the same machine, or could take over a second if it's on a remote server. Why don't you test it?

  3. #3
    Join Date
    Jul 2012
    Posts
    198
    Thanks
    54
    Thanked 3 Times in 3 Posts

    Default

    Thanks..
    what are the different methods which i can test it on my local machine. ?
    You will know the truth, and the truth will set you free (John 8:32)(The truth is about the only begotten son of GOD.....When you feel you are alone for facing your problems, God will never leave you by your own You are important for God

  4. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    The simplest method to benchmark (time) something, is to put it inside a function:
    PHP Code:
    function myBenchmark(){
        
    /*  bunches of code  */

    Then, take note of the time, run the function a few thousand times, then note the time again:
    PHP Code:
    $start microtimetrue );

    for( 
    $i=0$i<1000$i++ ){
        
    myBenchmark();
    }

    $elapsed_time microtimetrue ) - $start;
    print 
    $elapsed_time
    Then, do the same thing with the other method and compare the results.

    Some things to note:

    1) MAKE SURE everything happens the same way each time. If your code does something that affects the outside environment, for example (maybe you check for a variable and do some calculation if it doesn't exist - but then, on the next iteration, it does exist), then that would skew your results.

    2) 1,000 iterations is just an example; it's probably too few. Adjust the count until it takes at least a few seconds to finish. (Bigger numbers, smaller deviation.)

    3) Repeat this process a dozen or so times and take an average.

    This won't necessarily tell you which will work faster in real life, however. There are lots of considerations. It'll give you a starting point, though.

Similar Threads

  1. Replies: 0
    Last Post: 05-27-2012, 07:00 PM
  2. MySQL retrieval
    By twQ in forum PHP
    Replies: 7
    Last Post: 01-11-2010, 01:55 AM
  3. Replies: 2
    Last Post: 01-10-2009, 11:17 PM
  4. Ultimate Slideshow won't work with AJAX image retrieval
    By kenja in forum Dynamic Drive scripts help
    Replies: 12
    Last Post: 11-22-2008, 06:02 PM
  5. Remote retrieval & upload module for (BLOB)
    By dimmemo in forum MySQL and other databases
    Replies: 0
    Last Post: 07-04-2008, 01:43 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •