Author Topic: Prime Time  (Read 8837 times)

Offline AIR

  • BASIC Developer
  • Posts: 686
Re: Prime Time
« Reply #15 on: August 11, 2015, 08:32:43 PM »
Thanks for putting this together, Mike!

Offline John

  • Forum Support / SB Dev
  • Posts: 2791
    • ScriptBasic Open Source Project
Re: Prime Time
« Reply #16 on: August 12, 2015, 03:58:35 AM »
@Mike - I used the gcc -O3 option with the C BASIC example. It still amazes me that in one second the primes to a million are displayed in a terminal. At this point SB beats Perl???

Offline Mike Lobanovsky

  • (re)TIRED
  • BASIC Developer
  • Posts: 281
Re: Prime Time
« Reply #17 on: August 12, 2015, 05:13:25 AM »
I used the gcc -O3 option with the C BASIC example.

Yeah John, and that's what Armando did in his Mac-MBC too. I just wanted to have something equivalent in Windows to be able to disassemble it and see what makes -O3 run so fast. Remarkably, -O2 seems to preserve, more or less, the initial algo logic in its machine code as seen in my DynAsm script but makes the loops run approx. 2 times slower than -O3 putting static compilation on a par with my jitters. -O3 however reworks the innards entirely so that I simply cannot trace and understand the optimizations. Sometimes GCC is devilishly clever at that, which is absolutely awesome.
Mike
____________________________________________________________________
(3.6GHz Intel Core i5, 16GB RAM / nVidia GTX 1060Ti , 6GB VRAM / x64 Win7 Ult.)

Offline John

  • Forum Support / SB Dev
  • Posts: 2791
    • ScriptBasic Open Source Project
Re: Prime Time
« Reply #18 on: August 12, 2015, 04:55:22 PM »
I wonder if there is any noticeable difference between C and C++.


Offline AIR

  • BASIC Developer
  • Posts: 686
Re: Prime Time
« Reply #19 on: August 12, 2015, 05:36:05 PM »
There shouldn't be in this case, give it a try using g++ instead of gcc.

BTW, for Linux/OSX:

Code: C
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <sys/time.h>
  5.  
  6. int GetTickCount();
  7.  
  8. int main() {
  9.     int A, i, limit, gtc = GetTickCount();
  10.  
  11.     for (A = 1; A <= 1000000; A++) {
  12.       if (A % 2 == 0 && A > 2) continue;
  13.       limit = pow(A, 0.5) + 1;
  14.       for (i = 3; i <= limit; i++)
  15.         if (A % i == 0) goto iterate;
  16.       // comment this out for non-printable version
  17.       printf("%d\n", A);
  18.       iterate:;
  19.     }
  20.     printf("\nUptime: %.3f\n\nPress [enter] to continue...", (GetTickCount() - gtc) / 1000.0);
  21.     getchar();
  22.     return 0;
  23. }
  24.  
  25. int GetTickCount() {
  26.     struct timeval tv;
  27.     if( gettimeofday(&tv, NULL) != 0 )
  28.         return 0;
  29.     return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
  30. }

Offline John

  • Forum Support / SB Dev
  • Posts: 2791
    • ScriptBasic Open Source Project
Re: Prime Time
« Reply #20 on: August 12, 2015, 06:56:40 PM »
Thanks for the code AIR.

Not worth discussing over a hundredth of a second difference.


Offline John

  • Forum Support / SB Dev
  • Posts: 2791
    • ScriptBasic Open Source Project
Re: Prime Time
« Reply #21 on: August 13, 2015, 12:49:59 AM »
@Mike - I just read the BP.org drama queen thread. Paul deserves and Oscar. All BASIC is for people that are interested in sharing their knowledge about programming and not a forum for bitter Betty's that act like children.

Offline Mike Lobanovsky

  • (re)TIRED
  • BASIC Developer
  • Posts: 281
Re: Prime Time
« Reply #22 on: August 13, 2015, 05:02:49 AM »
@Armando:

Code: C
  1. .....................
  2. int GetTickCount() {
  3.     struct timeval tv;
  4.     if( gettimeofday(&tv, NULL) != 0 )
  5.         return 0;
  6.     return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
  7. }

in fact tells a lot about your personality; that would be very unusual to see from almost any other weather-bitten *nixoid. Thank you on behalf of seasoned Windows partisans! :D

As for Python and how it appeared in my possession, among the 2.9TB of Windows SW I've hosted on my workstation and used for decades now, there are only two proggies that would rely on concurrent Python 2.4 and Python 2.6 installations. The first one is respectively an older version of the weird GNU GPL piece of 3D model editing software called Blender, and the other one is a newer version of the same. By no means would I advocate for, or even look at if I can avoid it (which I can't when I'm under Linux), an interpreter that's able to fry a multi-core CPU in a few code lines of single-threaded process that's no worse than a tight empty loop. One has to be exceptionally elaborate to design a disastrous burn-in test for a modern CPU in any other -- saner -- language that I'm aware of.


@John: (or should it be Jon in Paul's notation? :) )

You know, I've grown me a callus on that side of my ego that's facing the BP's top blogger (that thread's OP), to substitute for the "ignore" functionality missing in their legacy forumware. It allows me to lurk, from time to time, in that far-away corner of contemporary BASIC scene as well. After all, there are a few creative persons there too like e.g. Paul or Jochen though of course none of them are by any means easy-goers either. Yet the wealth of info that can still be found, despite the overall decline, at the leading BASIC sites such as PB Peer Support Forums, Jose Roca's site, FreeBASIC's modern-syntax boards, and a few Russian and Latino VB6 forums, is incongruously more professional, instructive and practical for both beginners and advanced-level users of today. Interestingly, arguably the oldest but still rather active BASIC user can be frequently found not at BP dot org but rather at the BCX Yahoo group.

BCX BASIC! At 95 years of age, Carl!


Long live 5th generation BASICs! is all that comes to my mind. :)

Now take a seat and make yourself comfortable, John. I'm gonna tell you, George Carlin-style, an Oriental parable about Nasreddin Hodja, a witty and cunning but extremely poor Arab dervish, to illustrate why I wouldn't take part in the argument any further than I did.

They say one day the pauper Nasreddin Hodja brought home a purse full of gold and proudly put it on the table before his wife. "What's that? Did you steal it?", asked she suspiciously. "No, no! I made a bet with Padishah for ten thousand gold pieces that in the coming fifteen years I would, inshallah, teach my donkey to understand human speech and respond legibly. This gold is the thousand pieces I got as an advance to cater for the animal in the meantime", said Hodja. "You must be mad! You're gonna have your head chopped off!", gasped his wife and burst into tears. "There, there!", said Nasreddin patting his wife on the shoulder, "Nothing to worry about here, woman: I reconed in the fifteen years to come before I'm supposed to submit the results, either the donkey would die, or Padishah, or both".
Mike
____________________________________________________________________
(3.6GHz Intel Core i5, 16GB RAM / nVidia GTX 1060Ti , 6GB VRAM / x64 Win7 Ult.)

Offline John

  • Forum Support / SB Dev
  • Posts: 2791
    • ScriptBasic Open Source Project
Re: Prime Time
« Reply #23 on: August 13, 2015, 10:47:58 AM »
With some people, bitterness is incurable.

Thanks for the wisdom and your time!

Offline AIR

  • BASIC Developer
  • Posts: 686
Re: Prime Time
« Reply #24 on: August 13, 2015, 06:16:34 PM »
Thought I would throw NIM into the mix:

Code: Python
  1. from math import pow
  2.  
  3. for A in 1..1000000:
  4.     if A mod 2 == 0 and A > 2: continue
  5.     var limit = pow(float(A), 0.5) + 1
  6.     block iterate:
  7.         for i in 3..int(limit):
  8.             if A mod i == 0: break iterate
  9.         echo A

Offline John

  • Forum Support / SB Dev
  • Posts: 2791
    • ScriptBasic Open Source Project
Re: Prime Time
« Reply #25 on: August 13, 2015, 11:49:28 PM »
Quote
Thought I would throw NIM into the mix:

Can you post your results to give us an idea how it did?

Due to NIM compiling to C, are the results similar to MBC and C BASIC?
« Last Edit: August 14, 2015, 05:17:11 PM by John »

Offline AIR

  • BASIC Developer
  • Posts: 686
Re: Prime Time
« Reply #26 on: August 14, 2015, 01:18:33 PM »
See Below.

Offline John

  • Forum Support / SB Dev
  • Posts: 2791
    • ScriptBasic Open Source Project
Re: Prime Time
« Reply #27 on: August 14, 2015, 05:18:27 PM »
Thanks AIR!

Just what I thought. C results are all going to come out the same no matter how you started off.