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.nowfor i in 0..1337000000endfinish = Time.nowputs finish - start Python: 114.990328 (slowest) PHP: import timestart = time.clock()i = 0while i < 1337000000: i += 1end = time.clock()print(end - start)
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(i < 1337000000){ ++i; } printf("TIME: %.2fs\n", (double)(clock() - start)/CLOCKS_PER_SEC); return 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(i < 1337000000){ if(i == 1336999999){ std::cout << "I'm 1 number close: " << i << std::endl; } ++i; } printf("TIME: %.2fs\n", (double)(clock() - start)/CLOCKS_PER_SEC); return 0;} --------------------------------------------------- Edit: On NetBeans it outputs: TIME: 4.875s
I think I need to buy 8 4-bit counter ICs (integrated circuits) and connect it to a high-frequency AC supply. This is from the first Google Search result. Well... It still takes about two minutes.
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
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?
You actually haven't defined "count". So this works too. Code: TimeUnit.NANOSECONDS.sleep(1337000000); My program's nanosecond counter counted 1337000000 times.
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
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.
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.