1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

How fast and slow can your program count?

Discussion in 'Off-Topic' started by Primus, Nov 19, 2016.

  1. Primus

    Primus Zombie Pigman

    Messages:
    749
    This is simple challenge where you have to write program in any language which counts to 1337000000 and gets timing of that. There has to be two timings; fastest and slowest. Languages used may be different. Timing must be in seconds (real elapsed time) as a floating point.

    Rules: counting must be done on one thread, synchronized. No thread blocking function calls to slowdown the loop.

    This is the example of valid results.

    Ruby and Python:

    Ruby: 56.518135553 (fastest)
    PHP:
    start Time.now
    for i in 0..1337000000

    end
    finish 
    Time.now

    puts finish 
    start
    Python: 114.990328 (slowest)
    PHP:
    import time

    start 
    time.clock()
    0
    while 1337000000:
        
    += 1
    end 
    time.clock()
    print(
    end start)

     
  2. xBeastMode

    xBeastMode Shog Chips

    Messages:
    0
    C++
    Console output: TIME: 3.08s
    PHP:
    #include <iostream>
    #include <time.h>
    #include <string.h>

    int main(){
        
    int i 0;
        
    clock_t start clock();
        
        while(
    1337000000){
            ++
    i;
        }
        
    printf("TIME: %.2fs\n", (double)(clock() - start)/CLOCKS_PER_SEC);
        return 
    0;

    }
     
  3. xBeastMode

    xBeastMode Shog Chips

    Messages:
    0
    WTF??!! If you go to http://cpp.sh/ it says 0.00S

    Use this code for proof:

    PHP:
    #include <iostream>
    #include <time.h>
    #include <string.h>

    int main(){
        
    int i 0;
        
    clock_t start clock();
      
        while(
    1337000000){
            if(
    == 1336999999){
                
    std::cout << "I'm 1 number close: " << << std::endl;
            }
            ++
    i;
        }
        
    printf("TIME: %.2fs\n", (double)(clock() - start)/CLOCKS_PER_SEC);
        return 
    0;

    }
    ---------------------------------------------------

    Edit:
    On NetBeans it outputs:
    TIME: 4.875s
     
    Last edited: Nov 19, 2016
  4. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    This thread is more like "how fast can your machine count".
     
  5. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    Yup...
    I'll now get an i7 6700k, overclock it, just for this thread :p jk
     
  6. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    I think I need to buy 8 4-bit counter ICs (integrated circuits) and connect it to a high-frequency AC supply.
    upload_2016-11-20_17-9-27.png
    This is from the first Google Search result.
    Well... It still takes about two minutes.
     
  7. Primus

    Primus Zombie Pigman

    Messages:
    749
    It still depends on what language and how you code it, but you're the boss here :D
     
  8. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Depending on your definition of "program", I consider a set of integrated circuits a language too. Let me find an AC supply and a counter with 2.4 GHz frequency ;)
     
  9. Primus

    Primus Zombie Pigman

    Messages:
    749
    Hold on, is there actually a hardware for just counting? :D
     
  10. 99leonchang

    99leonchang Administrator Staff Member PMMP Team

    Messages:
    9
    GitHub:
    99leonchang
    [​IMG]
     
  11. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    XD
     
  12. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Yes. There are timer ICs and counter ICs. And basically all kinds of circuits that you can create with redstone.

    Now what about an assembly program?
     
  13. SuperPuperSteve

    SuperPuperSteve Creeper

    Messages:
    4
    Started counting with it, after 10 minutes - 6592
     
  14. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    You actually haven't defined "count".

    So this works too.
    Code:
    TimeUnit.NANOSECONDS.sleep(1337000000);
    
    My program's nanosecond counter counted 1337000000 times.
     
  15. Primus

    Primus Zombie Pigman

    Messages:
    749
    That's however is against rules because you can not use thread blocking function calls. I guess .sleep() is one. I'm trying to learn assembly programming :D
     
  16. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Every single statement is thread-blocking. Even increment is.

    If you insist:

    Code:
    long end = System.nanoTime() + 1337000000;
    while(end > System.nanoTime());
    You just ask me to count. You didn't require 1337000000 loops.
     
  17. Primus

    Primus Zombie Pigman

    Messages:
    749
    Not every statement is a function call

    I guess that it took 1337000000 + 10 nanoseconds to complete?
     
  18. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Every statement that executes something, including $i++, is thread-blocking. Fundamentally, all that non-native code can do is arithmetic calculations, copying, comparing and jumping execution pointers.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.