Rtalk Performance for micro benchmarks (how to improve)
Mark Roos
mroos at roos.com
Mon Sep 17 23:34:00 PDT 2012
An aside...can you post your RTALK and Java Hanoi impls? I'm
always
looking for another benchmark to add to my suite.
Not much but here, in order, would be Hanoi in Smalltalk, several integer
types of Java and the
version is java which matches the Rtalk implementation not using
invokeDynamic.
supportHanoiMove: numberOfDisks from: source to: dest temp: temp
"<modified:sys=GAKRE8CA,time=05/10/12 at 01:19:31 pm> "
numberOfDisks == 1 ifTrue: [^self].
self
supportHanoiMove: numberOfDisks - 1 from: source to: temp
temp: dest;
supportHanoiMove: numberOfDisks - 1 from: temp to: dest
temp: source
invoked with
self supportHanoiMove: 25 from: 1 to: 2 temp: 3
For the java tests ( I have tried all primitives and boxed as well )
public void testMove(Long numberOfDisks, Long source, Long dest, Long
temp) {
Long one = 1L;
if(numberOfDisks.longValue() == one.longValue()) return;
testMove(new Long(numberOfDisks-1L), source, temp, dest);
testMove(new Long(numberOfDisks-1L), temp, dest, source);
}
And for the Rtalk equivalent ( without BigInteger ) RtObject boxes a
long
public void testMove(RtObject numberOfDisks, RtObject source, RtObject
dest, RtObject temp) {
RtObject one = new RtObject(1L);
if(RtPrimitives.primObjectIdentEquals(numberOfDisks, one) == RtObject.
getTrue()) return;
RtObject next = RtPrimitives.primIntegerSub(numberOfDisks, one);
testMove(next, source, temp, dest);
next = RtPrimitives.primIntegerSub(numberOfDisks, one);
testMove(next, temp, dest, source);
}
Where
static public RtObject primObjectIdentEquals(RtObject rcvr, RtObject
arg1) {
// need to handle integer special
if((rcvr.shape() == 1) & (arg1.shape() == 1)){
if(rcvr.getLongValue() == arg1.getLongValue()){
return RtObject._true;
}
}
else{
if (rcvr == arg1) {
return RtObject._true;
}
}
return RtObject._false;
static public RtObject primIntegerSub(RtObject rcvr, RtObject arg1) {
if((arg1.shape() & 0x1) != 1){
return _primFail;
}else{
long c=(rcvr.getLongValue()) - (arg1.getLongValue());
return RtObject.newInteger(c);
}
}
public static RtObject newInteger(long val){
// use cache to get one or else make a new one
// check for overflow which is > 62bit signed
if (val < -2305843009213693952L || val > 2305843009213693951L) {
return newBigInteger(BigInteger.valueOf(val));
}
if(val >= _intCacheMin && val <= _intCacheMax){
return _integerCache[(int)val - (int)_intCacheMin];
}else{
return new RtObject(val);
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/mlvm-dev/attachments/20120917/7f2e5332/attachment-0001.html
More information about the mlvm-dev
mailing list