Page 2 of 2 FirstFirst 12
Results 11 to 13 of 13

Thread: [Any] A quick speed tip

  1. #11
    BlackSheep's Avatar
    Joined
    Jan 2012
    Posts
    192
    Userbars
    3
    Thanks
    20
    Thanked
    24/20
    DL/UL
    10/0
    Mentioned
    26 times
    Time Online
    1d 1h 55m
    Avg. Time Online
    N/A
    I feel as if im among gods reading this jibberish lol... I want to learnnnnn so I can be 1337.... <--- is that the term? ... ./m just seems like one of many awesome username's one could have if they knew all of this lol.. teach me your ways

  2. #12
    Zachafer's Avatar
    Joined
    Dec 2011
    Posts
    1,235
    Userbars
    11
    Thanks
    769
    Thanked
    1,466/678
    DL/UL
    98/0
    Mentioned
    512 times
    Time Online
    24d 13h 9m
    Avg. Time Online
    8m
    Another loop speed tip

    Consider this first loop:
    PHP Code:
    $total 0;
    $factor 100;
    for(
    $x 0$x 50$x++) {
        for(
    $y 0$y 50$y++) {
            
    $total += ($x $y) + ($x $factor) + ($y $factor);
        }

    $x * $factor is repeated 50 unnecessary times per iteration.

    PHP Code:
    $total 0;
    $factor 100;
    for(
    $x 0$x 50$x++) {
        
    $xfactor $x $factor;
        for(
    $y 0$y 50$y++) {
            
    $total += ($x $y) + $xfactor + ($y $factor);
        }


  3. The Following 2 Users Say Thank You to Zachafer For This Useful Post:

    Miguel (03-11-2012),npm (11-24-2012)

  4. #13

    Joined
    Aug 2013
    Posts
    6
    Userbars
    0
    Thanks
    0
    Thanked
    0/0
    DL/UL
    10/0
    Mentioned
    Never
    Time Online
    6h 25m
    Avg. Time Online
    N/A
    Quote Originally Posted by bamag View Post
    ...C++ looks so similar to Java :o
    well, they're both C-based languages

    ---------- Post added at 04:54 AM ---------- Previous post was at 04:47 AM ----------

    basic rule with loops/looping-mechanisms...

    use for if you know how many times you wish to repeat the test

    use do while if you wish to execute the test/loop AT LEAST ONCE, and then perform successive test(s) to see if condition still applies (prior to looping again)

    use while ONLY when you don't know how many times you wish to repeat the test, as while loops are more resource intensive.

    ---------- Post added at 05:04 AM ---------- Previous post was at 04:54 AM ----------

    Quote Originally Posted by Jehuty View Post
    ...the time it takes the compiler to declare and set an additional variable is barely measurable.
    with today's computers, you are correct UNLESS you're filtering through a large amount of data.

    yet "back in the day", when programmers only had 15-32k of RAM to work with, very strict methods/practices were adopted to manage that memory which would be viewed by today's programmer's as unnecessary; yet the trade-off is that programmer's today are not as resource conscious as they used to be and have a tendency of creating unnecessarily resource-intensive, or resource-hogging methods/functions/programs, simply because we haven't been as nearly constricted as our predecessors. But a good purist will always point these things out, or these factors are only worth looking in to when a program achieves a bottleneck... a good example would be when a C++ programmer is coding a game, only has a certain amount of memory that can be utilized at any given time, and may find it necessary to write in assembly (or even machine) in order to achieve optimal speed.

    Likewise, dudes in the olden days used to be more familiar with machine and assembly than today's programmers; as today's programmers are way super spoiled and are developing on computers with (at least) 4GB RAM, and (at least) 2 GhZ CPU

Posting Permissions

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