Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Best Language For Number Crunching
#11
Quote:What would be next best after ASM? C++ right?
FORTRAN. Wink
Reply
#12
13,983,816 combinations in 1:50 to be exact. (I have an Athlon 2800.) The log file is 332 MB.

DEFINT A-Z makes the default data type integer, which is much faster than using singles (the default type otherwise). Since most of your numbers are integer, this helps a lot. The & on counter& forces the data type of counter to long integer to prevent an overflow.
Reply
#13
If you were using a 32-bit compiler, you could make it even faster, since LONG arithmetic in QB 4.5 really stinks - the compiler only generates 8086 code, so it can't use the 32-bit "e" registers for 32-bit integer math.
Reply
#14
Later versions of QB support 386 CPUs, don't it?

That definately where it drops off, though.
Reply
#15
VBDOS has a compiler switch /G3 to use 386 instructions, but that's it as far as I know. PDS has a /G2 switch to use 286 instructions.
Reply
#16
VBDOS /G3 switch only affect your code, the runtime libraries are 8086 code.

So the speed increase would be minimal.


PDS has /G2, which makes it a tiny bit faster, nothing you'd notice, and again, the runtime libraries are still 8086 code... sucks...


Code:
Print "blah!"
Would be just as fast, no matter if you used /g2, /g3 or nothing, as most of the program is runtime libraries that you have no controll over (unless your name is plasma Tongue )

There might be an extremely small increase in the string handling stuff, but it's neglectable.

Nevertheless, /G2 in PDS generates EXE's that (in some cases) are a few bytes smaller, so if size is an important thing, then /G2 can be used.



Over at Pete's QB Site, in the zines (magazines) section, you can find some good info on commandline options, and compiler settings, for almost all versions of QB. If nothing else, it's a pretty good read, lot's of usefull information.
Reply
#17
The place where 386 instructions come in handy here is in the LONG arithmetic, not in the calls to standard library routines.
Reply
#18
Remember, a lot of speed is going to be removed if you are PRINTing every loop. Notice that Plasma moved the PRINT "blah number of combintations" to the outer FOR NEXT loop. This saves a hell of a lot of time.

Also, the printing to the file will slow the program down a lot. Try it without the recording to the file and you will notice another major speed increase.

Finally, plasma added DEFINT A-Z. You say you dont know what this does, but as Plasma explained, it automatically makes all the datatypes as integers. These are much faster than floating point numbers, because of a bug in QB.
Reply
#19
Even with FFIX, integer math is faster than floating point.
Reply
#20
I wrote a similar program a while back, though not as fast because it has other features like matching the numbers with drawn numbers, and other stuff.
Take a look, you can change the coloums and rows for different wheels. Also uses a recursive sub, so it's kinda cool,
check it out...

Code:
'''
' POTWHEEL v1.1, a pure Quick-BASIC 4.5, lottery number wheeling program.
'
' (C)opyright 2003, Pure QB Innovations
'
' Contact me at ESmemberNEMESIS@aol.com
' If you have any questions or comments concerning these routines.
'
' THIS PROGRAM MAY BE DISTRIBUTED FREELY AS PUBLIC DOMAIN SOFTWARE
' AS LONG AS ANY PART OF THIS FILE IS NOT ALTERED IN ANY WAY.
' IF YOU DO WISH TO USE THESE ROUTINES IN YOUR OWN PROGRAMS
' THEN PLEASE GIVE CREDIT TO THE AUTHOR... Mario LaRosa.
'
'''
'
DEFINT A-Z
'
CONST coloums = 6
CONST rows = 42
'
DECLARE SUB wheel (c)
'
DIM SHARED drawn(coloums)
DIM SHARED number(coloums)
DIM SHARED prizes&(coloums)
'
DIM SHARED match, cost&, winnings&, K$
'
SCREEN 0: WIDTH 80: COLOR 7: CLS
'
IF coloums >= rows THEN SYSTEM
'
''' Prizes simulated from  /^\/\COLORADO/\/^\  6-pick lottery game.
'
prizes&(1) = 0
prizes&(2) = 0
prizes&(3) = 4
prizes&(4) = 49
prizes&(5) = 825
prizes&(6) = 12000000
'
''' Custom draw...
'
'drawn(1) = 13
'drawn(2) = 21
'drawn(3) = 7
'drawn(4) = 28
'drawn(5) = 33
'drawn(6) = 40
'
''' Random draw... (Quick pick!)
'
RANDOMIZE TIMER
'
DO
d = INT(RND(1) * rows + 1)
FOR x = 1 TO coloums
  IF d = drawn(x) THEN EXIT FOR
  IF x = coloums THEN
   IF p = coloums THEN EXIT DO
   p = p + 1
   drawn(p) = d
  END IF
NEXT
LOOP
'
p = 0
'
FOR x = (coloums - 1) TO 0 STEP -1
FOR s = coloums TO 1 STEP -1
  IF drawn(x) > drawn(s) THEN
   SWAP drawn(x), drawn(s)
  END IF
NEXT
NEXT
'
odds& = 1
FOR x = 1 TO coloums
odds& = odds& * ((rows + 1) - x) / x
NEXT
'
COLOR 7
LOCATE 1, 1: PRINT "Odds: 1 in"; odds&
LOCATE 2, 1: PRINT "Cost: $"; 1
LOCATE 3, 1: PRINT "Wins: $"
LOCATE 4, 1: PRINT "Match:"
LOCATE 5, 1: PRINT "Drawn:"
LOCATE 6, 1: PRINT "Plays:"
LOCATE 8, 1: PRINT "[ ]ontinue, [ ]ause, [ ]uit"
COLOR 15
LOCATE 8, 2: PRINT "C"
LOCATE 8, 14: PRINT "P"
LOCATE 8, 23: PRINT "Q"
COLOR 7
'
FOR x = 1 TO coloums
LOCATE 5, 5 + (x * 3): PRINT drawn(x)
NEXT
'
K$ = "p"
'
wheel 1
'
SYSTEM
'

SUB wheel (c)
'
IF c > coloums THEN
  cost& = cost& + 1
  LOCATE 2, 8: PRINT cost&
  FOR z = 1 TO coloums
   FOR s = 1 TO coloums
    IF number(z) = drawn(s) THEN
     match = match + 1
     md = s
     mn = z
     EXIT FOR
    END IF
   NEXT
   LOCATE 5, 5 + (z * 3): PRINT drawn(z)
   LOCATE 6, (5 + (z * 3)): PRINT number(z)
   IF md THEN
    COLOR match
    LOCATE 5, 5 + (md * 3): PRINT drawn(md)
    md = 0
    COLOR 7
   END IF
   IF mn THEN
    COLOR match
    LOCATE 6, (5 + (mn * 3)): PRINT number(mn)
    md = 0
    COLOR 7
   END IF
  NEXT
  IF match THEN
   COLOR match
   winnings& = winnings& + prizes&(match)
  END IF
  LOCATE 4, 8: PRINT match
  IF match = coloums THEN
   LOCATE 10, 10: PRINT "!!!Jackpot!!!"
   DO
    K$ = INKEY$
    snd = snd + 10
    SOUND 200 + snd, 1
    IF snd = 200 THEN snd = 0
   LOOP UNTIL LEN(K$)
   LOCATE 10, 10: PRINT "             "
  END IF
  match = 0
  COLOR 7
  LOCATE 3, 8: PRINT winnings&
  IF UCASE$(K$) = "P" THEN SLEEP
  K$ = INKEY$
  IF UCASE$(K$) = "Q" THEN SYSTEM
ELSE
  FOR x = 1 + number(c - 1) TO rows
   number(c) = x
   wheel c + 1
  NEXT
END IF
'
END SUB

Cya!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)