- Speed test. Clarification
----boundary-LibPST-iamunique-1718104821_-_-
Content-type: text/plain
That ought to teach me not to post partial code. The complete programs are posted below (I added timers).
I made the arrays big, (1) so I didn't have to bother with timers in three compilers, and (2) to make sure they wouldn't fit in the cache. For comparing compilers, I wanted to avoid erratic results due to the cache.
I like Wojtek's program, though. Caching makes almost a threefold improvement in speed on my computer, so yes, memory is the bottleneck.
I played a little more with unrolling the loop. Unrolling 5 times gave an 18% improvement with an array length of 100, but it was 2% worse with a length of 1,000,000. Your mileage may vary.
There is one other inconvenient truth, however. With the FORTRAN program, with an array size of around 15,000 or lower (number of arithmetic operations constant), so everything fit in the cache, the operation was astonishingly fast -- 2 1/2 seconds, compared to 10 seconds at best for BB. But again, that's an unfair comparison, because with range checking, FORTRAN takes 10 minutes 30 seconds!
Rex Couture
=======
MODULE TestTime;
IMPORT StdLog, Services;
VAR
a, b: ARRAY 1000000 OF REAL;
i, j: INTEGER;
sum: REAL;
t0: LONGINT;
PROCEDURE Do*;
BEGIN
t0:= Services.Ticks();
sum:= 0;
FOR j:= 0 TO 199 DO
FOR i:= 0 TO 999999 DO
a[i]:= i-j;
b[i]:= i-j;
END;
FOR i:= 0 TO 999999 DO
sum:= sum +a[i]*b[i];
END;
END;
StdLog.Int((Services.Ticks() - t0));
StdLog.Real( sum); StdLog.Ln
END Do;
========
MODULE TestTime2; (* Unrolls loop *)
IMPORT StdLog, Services;
VAR
a, b: ARRAY 1000000 OF REAL;
i, j: INTEGER;
sum: REAL;
t0: LONGINT;
PROCEDURE Do*;
BEGIN
t0:= Services.Ticks();
sum:= 0;
FOR j:= 0 TO 199 DO
FOR i:= 0 TO 999999 BY 5 DO
a[i]:= i-j;
b[i]:= i-j;
a[i+1]:= i-j;
b[i+1]:= i-j;
a[i+2]:= i-j;
b[i+2]:= i-j;
a[i+3]:= i-j;
b[i+3]:= i-j;
a[i+4]:= i-j;
b[i+4]:= i-j;
END;
FOR i:= 0 TO 999999 BY 5 DO
sum:= sum +a[i]*b[i];
sum:= sum +a[i+1]*b[i+1];
sum:= sum +a[i+2]*b[i+2];
sum:= sum +a[i+3]*b[i+3];
sum:= sum +a[i+4]*b[i+4];
END;
END;
StdLog.Int((Services.Ticks() - t0));
StdLog.Real( sum); StdLog.Ln
END Do;
END TestTime2.
--- BlackBox
--- send subject HELP or UNSUBSCRIBE to blackbox{([at]})nowhere.xy
----boundary-LibPST-iamunique-1718104821_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"
e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzcyBBcmlhbDt9DQp7XGYxXGZtb2Rlcm4gQ291cmllciBOZXc7fQ0Ke1xmMlxmbmlsXGZjaGFy
c2V0MiBTeW1ib2w7fQ0Ke1xmM1xmbW9kZXJuXGZjaGFyc2V0MCBDb3VyaWVyIE5ldzt9fQ0Ke1xj
b2xvcnRibFxyZWQwXGdyZWVuMFxibHVlMDtccmVkMFxncmVlbjBcYmx1ZTI1NTt9DQpcdWMxXHBh
cmRccGxhaW5cZGVmdGFiMzYwIFxmMFxmczIwICAgICAgICAgVGhhdCBvdWdodCB0byB0ZWFjaCBt
ZSBub3QgdG8gcG9zdCBwYXJ0aWFsIGNvZGUuICBUaGUgY29tcGxldGUgcHJvZ3JhbXMgYXJlIHBv
c3RlZCBiZWxvdyAoSSBhZGRlZCB0aW1lcnMpLlxwYXINClxwYXINCiAgICAgICAgSSBtYWRlIHRo
ZSBhcnJheXMgYmlnLCAoMSkgc28gSSBkaWRuJ3QgaGF2ZSB0byBib3RoZXIgd2l0aCB0aW1lcnMg
aW4gdGhyZWUgY29tcGlsZXJzLCBhbmQgKDIpIHRvIG1ha2Ugc3VyZSB0aGV5IHdvdWxkbid0IGZp
dCBpbiB0aGUgY2FjaGUuICBGb3IgY29tcGFyaW5nIGNvbXBpbGVycywgSSB3YW50ZWQgdG8gYXZv
aWQgZXJyY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ICAgYSwgYjogQVJSQVkgMTAwMDAwMCBPRiBSRUFMO1xwYXIN
CiAgICAgICAgaSwgajogSU5URUdFUjtccGFyDQogICAgICAgIHN1bTogUkVBTDtccGFyDQogICAg
ICAgIHQwOiBMT05HSU5UO1xwYXINClxwYXINClBST0NFRFVSRSBEbyo7XHBhcg0KQkVHSU5ccGFy
DQp0MDo9IFNlcnZpY2VzLlRpY2tzKCk7XHBhcg0Kc3VtOj0gMDtccGFyDQpGT1Igajo9IDAgVE8g
MTk5IERPXHBhcg0KICAgICAgICBGT1IgaTo9IDAgVE8gOTk5OTk5IEJZIDUgRE9ccGFyDQogICAg
ICAgICAgICAgICAgYVtpXTo9IGktajtccGFyDQogICAgICAgICAgICAgICAgYltpXTo9IGktajtc
cGFyDQogICAgICAgICAgICAgICAgYVtpKzFdOj0gaS1qO1xwYXINCiAgICAgICAgICAgICAgICBi
W2krMV06PSBpLWo7XHBhcg0KICAgICAgICAgICAgICAgIGFbaSsyXTo9IGktajtccGFyDQogICAg
ICAgICAgICAgICAgYltpKzJdOj0gaS1qO1xwYXINCiAgICAgICAgICAgICAgICBhW2krM106PSBp
LWo7XHBhcg0KICAgICAgICAgICAgICAgIGJbaSszXTo9IGktajtccGFyDQogICAgICAgICAgICAg
ICAgYVtpKzRdOj0gaS1qO1xwYXINCiAgICAgICAgICAgICAgICBiW2krNF06PSBpLWo7XHBhcg0K
ICAgICAgICAgICAgICAgIEVORDtccGFyDQogICAgICAgIEZPUiBpOj0gMCBUTyA5OTk5OTkgQlkg
NSBET1xwYXINCiAgICAgICAgICAgICAgICBzdW06PSBzdW0gK2FbaV0qYltpXTtccGFyDQogICAg
ICAgICAgICAgICAgc3VtOj0gc3VtICthW2krMV0qYltpKzFdO1xwYXINCiAgICAgICAgICAgICAg
ICBzdW06PSBzdW0gK2FbaSsyXSpiW2krMl07XHBhcg0KICAgICAgICAgICAgICAgIHN1bTo9IHN1
bSArYVtpKzNdKmJbaSszXTtccGFyDQogICAgICAgICAgICAgICAgc3VtOj0gc3VtICthW2krNF0q
YltpKzRdO1xwYXINCiAgICAgICAgICAgICAgICBFTkQ7XHBhcg0KICAgICAgICBFTkQ7XHBhcg0K
U3RkTG9nLkludCgoU2VydmljZXMuVGlja3MoKSAtIHQwKSk7XHBhcg0KU3RkTG9nLlJlYWwoIHN1
bSk7IFN0ZExvZy5MblxwYXINCkVORCBEbztccGFyDQpccGFyDQpFTkQgVGVzdFRpbWUyLiBccGFy
DQpccGFyDQotLS0gQmxhY2tCb3hccGFyDQotLS0gc2VuZCBzdWJqZWN0IEhFTFAgb3IgVU5TVUJT
Q1JJQkUgdG8gYmxhY2tib3hAb2Jlcm9uLmNoXHBhcg0KXHBhcg0KfQ==
----boundary-LibPST-iamunique-1718104821_-_---
Received on Fri Nov 03 2006 - 22:05:05 UTC
This archive was generated by hypermail 2.3.0
: Thu Sep 26 2013 - 06:32:09 UTC