Post Reply 
Mersenne Twister implentation
02-06-2017, 07:58 AM
Post: #5
RE: Mersenne Twister implentation
This is what I used to benchmark the two methods. No comments in the code because it is fairly self-explanatory:
Code:
MethA();
MethB();
TimeMethA(n);
TimeMethB(n);

EXPORT LISTTIME(n)
BEGIN
LOCAL a, b;
 a:=TimeMethA(n);
 b:=TimeMethB(n);
 STRING(a)+" / "+STRING(b)+" = "+STRING(a/b);
END;

EXPORT TimeMethA(n)
BEGIN
 LOCAL b4:=TICKS, after, j;
 FOR j FROM 1 TO n DO
  MethA(); 
 END;
 after:=TICKS;
 RETURN after-b4; 
END;

EXPORT TimeMethB(n)
BEGIN
 LOCAL b4:=TICKS, after, j;
 FOR j FROM 1 TO n DO
  MethB();
 END;
 after:=TICKS;
 RETURN after-b4; 
END;

MethA()
BEGIN
 LOCAL k;
 L9:={};
 FOR k FROM 1 TO 624 DO
  L9(k):=#0d;
 END;
END;

MethB()
BEGIN
 L9:=MAKELIST(#0d,A,1,624);
END;
On a real device with display set to FIX 2:

LISTTIME(1) yields: "91.00 / 4.00 = 22.75"
LISTTIME(10) yeilds: "791.00 / 55.0 = 14.38
LISTTIME(100) yields: "7709.00 / 561.00 = 13.74"
LISTTIME(1000) yields: "77041.00 / 5617.00 = 13.72"

On an emulated Prime, also with display set to FIX 2:

LISTTIME(1) gives a division by zero because method B completes in less than a millisecond.
LISTTIME(10): "16.00 / 1.00 = 16.00"
LISTTIME(100): "159.00 / 10.00 = 15.90"
LISTTIME(1000): "1580.00 / 98.00 = 16.12"
LISTTIME(10000): "15528.00 / 975.00 = 15.93"
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Mersenne Twister implentation - KeithB - 02-04-2017, 04:19 PM
RE: Mersenne Twister implentation - grsbanks - 02-06-2017 07:58 AM
RE: Mersenne Twister implentation - KeithB - 02-06-2017, 04:42 PM
RE: Mersenne Twister implentation - KeithB - 02-06-2017, 07:08 PM



User(s) browsing this thread: 1 Guest(s)