Re: Larkin, Power BASIC cannot be THAT good:
- From: John Larkin <jjlarkin@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 10 Jul 2009 13:07:01 -0700
On Fri, 10 Jul 2009 10:42:42 -0700 (PDT), blackhead
<larryharson@xxxxxxxxxxxx> wrote:
On 16 May, 18:49, John Larkin
<jjlar...@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
On Sat, 16 May 2009 10:17:39 -0700 (PDT), Tim Williams
<tmoran...@xxxxxxxxx> wrote:
On May 16, 10:06 am, John Larkin
<jjlar...@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
On Sat, 16 May 2009 06:31:37 -0700, xray <n...@xxxxxxxxxxx> wrote:
On Fri, 15 May 2009 11:27:55 -0700, John Larkin
<jjlar...@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
On Fri, 15 May 2009 14:34:51 GMT, Jan Panteltje
<pNaonStpealm...@xxxxxxxxx> wrote:
The run time in C is 13 seconds here on a 1GHz processor.
Can you specify your 'old HP computer' ?
I can win maybe 1 second by writing the code a bit different.
And a 3GHz would do it in 12 / 4 = 4 seconds...
A bigger cache would help a bit perhaps.
A Cray would be even better.
What does you C code look like? Mine is in the other posting.
Else you goofed a factor 10.
Seems to me anyways :-)
Here's my PowerBasic code:
===================================================
#COMPILE EXE
' SUM.BAS
' TRY SUMMING A LOT OF INTS INTO AN ARRAY OF LONGS...
' JL MAY 14, 2009 PBCC4
FUNCTION PBMAIN () AS LONG
COLOR 15,9
CLS
DIM A(64000000) AS INTEGER ' INPUT ADC SAMPLES
DIM S(64000000) AS LONG ' SUMMING ARRAY
DIM X AS LONG
DIM Y AS LONG
DIM Z AS LONG
' INIT INPUT ARRAY TO RANDOM-ISH VALUES...
FOR X = 1 TO 64000000 ' THIS IS MUCH FASTER
A(X) = X AND 32767 ' THAN CALLING RND()!
NEXT
T! = TIMER
PRINT "Start... ";
FOR Y = 1 TO 10
FOR X = 1 TO 64000000
S(X) = S(X) + A(X)
NEXT
NEXT
PRINT "Done"
E! = TIMER - T!
PRINT USING$("Time per loop ##.### sec ##.## ns/add", E!/10, 1E9*E!/(10*64E6))
' DISPLAY SOME RESULTS TO MAKE SURE IT REALLY WORKED...
FOR X = 1 TO 10
PRINT X, A(X), S(X)
NEXT
FOR X = 63999001 TO 63999010
PRINT X, A(X), S(X)
NEXT
INPUT A$
END FUNCTION
===================================================
On my computer, a 1.9 GHz Xeon with 2G ram, winXP, I get this
result...
Start... Done
Time per loop 0.231 sec 3.61 ns/add
1 1 10
2 2 20
3 3 30
4 4 40
5 5 50
6 6 60
7 7 70
8 8 80
9 9 90
10 10 100
63999001 3097 30970
63999002 3098 30980
63999003 3099 30990
63999004 3100 31000
63999005 3101 31010
63999006 3102 31020
63999007 3103 31030
63999008 3104 31040
63999009 3105 31050
63999010 3106 31060
===================================================
One of my guys did a C version (I refuse to program in C) to run on
the Kontron under Linux, a slightly slower CPU, 2G ram. I asked him
for his source code, and he spent about a half hour cleaning it up to
be presentable... which I asked him NOT to do. Anyhow, here it is:
* mathsmash.c - a VERY crude benchmark
*
* time the sum of 64-million 16-bit integers into 64-million 32-integer sums.
*
* gcc -O3 mathsmash.c -o mathsmash.o
*
* NOTE: The loop is performed 10 times to make the measurement duration more reasonable.
*
* Timing is done by observation or including the system("date") functions.
*
*
*/
#define SIXTYFOURMILLION (0x100000 * 64)
#define DATA_ARRAY_SIZE SIXTYFOURMILLION
#include <stdio.h>
int main()
{
unsigned short *inbound_data;
unsigned int *sum_data;
int multiply;
unsigned long index = 0;
#if 0
/* Initialize data */
printf ("Zeroing data\n");
#endif
inbound_data = (unsigned short *) malloc (sizeof ( short ) *
DATA_ARRAY_SIZE);
sum_data = (unsigned *) malloc ((sizeof ( int )) *
DATA_ARRAY_SIZE);
printf ("inb_ptr = 0x%08x, sum_ptr= 0x%08x\n", inbound_data,
sum_data);
printf ("\n START sum operation...\n");
// system ("date");
for (multiply = 0; multiply < 10; multiply ++) // 10 x
{
for ( index = 0; index < DATA_ARRAY_SIZE; ++index )
sum_data[index] += inbound_data[index];
}
printf ("\n END sum operation...\n");
// system ("date");
}
===================================================
He commented out the system date things because they're buggy or
something, and timed it with his wristwatch at about 0.25 seconds per
64M add, about the same as the PowerBasic.
He used subscripts, not pointers, as I did. The inner loop compiles to
five instructions.
My program is prettier.
John
Re: My program is prettier.
I don't think so. For one thing your program is shouting.
Real programmers don't use lower case.
John
Nah. Real Programmers don't use anything with 'case' at all. (Which
I guess includes binary, octal and decimal, as well as any entry
method, especially panel switches.)
Tim
The impressive thing about C and C++, as languages and as a culture,
is that as programmers become more experienced and "skilled", the
readability of their code drops and the bug rate remains high.
John- Hide quoted text -
- Show quoted text -
Programmers learn to organise the information in their program so that
it doesn't swamp out the program itself. Hence, they keep commenting,
caps etc to a minimum. It's exactly the same with drawing out a
schematic - information is kept to a minimum so it doesn't swamp the
circuit, such as not using long power supply or ground lines when a
short vcc or gnd label will do.
That makes me yet-again grateful that I'm not a programmer.
I comment my code and my schematics. And my breadboards even.
I never understood the appeal of destroying information. Is it a job
security thing?
You'll hate this. Think how much better it would be without comments:
.SBTTL . MAXIM : LOAD A SERIAL DAC
; THE MAXIM SERIAL DAC NEEDS 4 BITS OF CONTROL AND 12 BITS
; OF DATA. THE PATTERNS ARE...
MAXA = 0000h ; 0ddd LOAD DAC A 10 MHZ XO TRIM
MAXB = 1000h ; 1ddd LOAD DAC B 50 MHZ OSC TRIM
MAXC = 2000h ; 2ddd LOAD DAC C TRIGGER LEVEL
MAXD = 3000h ; 3ddd LOAD DAC D DPLL ADC REF
WAKA = 0F000h ; WAKE UP DAC A
TRISA = 0F001h ; TRISTATE DAC A
WAKB = 0F004h ; WAKE UP DAC B
WAKC = 0F008h ; WAKE UP DAC C
WAKD = 0F00Ch ; WAKE UP DAC D
; ENTER HERE WITH D4 LOADED WITH A 16-BIT PATTERN, 4 BITS
; OF COMMAND FOLLOWED BY 12 BITS OF DATA.
MAXIM: MOVEM.L D4 D7 A2, -(SP) ; PROTECT REGGIES
MOVEA.W # PORTD, A2 ; AIM AT THE I/O PORT
BMX = 4 ; MAC DAC CS- BITNUM
CLK = 2 ; SPI CLOCK
DAT = 1 ; SERIAL DATA OUT
BCLR.B # CLK, (A2) ; MAKE SURE CLOCK IS LOW AND
BCLR.B # BMX, (A2) ; PULL DOWN MAX CS-
MOVE.W # 16-1, D7 ; WE'LL BANG 16 BITS
LD16: ASL.W # 1, D4 ; TEST A BIT...
BCS.S MAX1 ; HOP FOR '1'
BCLR.B # DAT, (A2) ; DATA LOW
BRA.S MAXCLK
MAX1: BSET.B # DAT, (A2) ; DATA HIGH
MAXCLK: BSET.B # CLK, (A2) ; POP THE CLOCK HIGH
BCLR.B # CLK, (A2) ; AND LOW
DBF D7, LD16 ; LOOP FOR 16 BITS
BSET.B # BMX, (A2) ; RELEASE CHIP SELECT
MOVEM.L (SP)+, D4 D7 A2
RTS
John
.
- References:
- Re: Larkin, Power BASIC cannot be THAT good:
- From: blackhead
- Re: Larkin, Power BASIC cannot be THAT good:
- Prev by Date: Re: OT: This is why there are "denialists"...
- Next by Date: Re: OT: This is why there are "denialists"...
- Previous by thread: Re: Larkin, Power BASIC cannot be THAT good:
- Next by thread: Re: timing pulley becoming magnetized (PROXIMITY) issue.
- Index(es):
Relevant Pages
|