??? 02/18/05 15:34 Read: times |
#87884 - test Responding to: ???'s previous message |
I quickly wrote a test in Pascal, given below, which could be converted to '51 quite straighforwardly.
When changing the number of bytes up to n=128, on the PC (a vintage 100MHz Pentium) the execution time grew with a squre of n: n t[ms] 4 0.13 8 0.46 16 1.60 32 6.25 64 24.73 128 44.46 (hum, a deviation - I don't know why...) This may give a rough estimation. Jan Waclawek var a,b:array[0..127] of byte; r:array[0..255] of byte; ai,bi,ri,n:integer; ab:word; atemp, btemp, cy:byte; function dec2hex(b:byte):string; const nib2hex:array[0..$F] of char = ('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); begin dec2hex:=nib2hex[b shr 4]+nib2hex[b and $F]; end; begin n:=4; a[3]:=$01; a[2]:=$23; a[1]:=$45; a[0]:=$67; b[3]:=$89; b[2]:=$ab; b[1]:=$cd; b[0]:=$ef; { a[3]:=$FF; a[2]:=$FF; a[1]:=$FF; a[0]:=$FF; b[3]:=$FF; b[2]:=$FF; b[1]:=$FF; b[0]:=$FF; } for ri:=0 to n*n do r[ri]:=0; for ai:=0 to n-1 do begin for bi:=0 to n-1 do begin ab:=a[ai]*b[bi]; atemp:=ab and $FF; btemp:=ab shr 8; ri:=ai+bi; ab:=r[ri]+atemp; r[ri]:=ab and $FF; cy:=ab shr 8; inc(ri); ab:=r[ri]+btemp+cy; r[ri]:=ab and $FF; cy:=ab shr 8; while cy>0 do begin inc(ri); ab:=r[ri]+cy; r[ri]:=ab and $FF; cy:=ab shr 8; end; end; end; for ai:=n-1 downto 0 do write(dec2hex(a[ai])); write(' * '); for bi:=n-1 downto 0 do write(dec2hex(b[bi])); write(' = '); for ri:=(n+n)-1 downto 0 do write(dec2hex(r[ri])); writeln; end. |
Topic | Author | Date |
Push and Pop | 01/01/70 00:00 | |
Loop | 01/01/70 00:00 | |
Wrong value | 01/01/70 00:00 | |
Expanding | 01/01/70 00:00 | |
re:expanding | 01/01/70 00:00 | |
possible - yes. practical - no | 01/01/70 00:00 | |
:) | 01/01/70 00:00 | |
not scientific | 01/01/70 00:00 | |
Hmm | 01/01/70 00:00 | |
test | 01/01/70 00:00 | |
a small correction to the previous post | 01/01/70 00:00 | |
:)![]() | 01/01/70 00:00 |