Here is another implementation which makes fib2_3 twice as fast for me
(~32s vs. ~14s). Unless I missed something, that actually puts it as
fast as (or maybe slightly faster than) Ruby 1.8.7.
//No changes to Object
Integer = $new(null)
Integer.cache = $hnew(10) //keep a cache of integer
[...]
The issue here is that you will waste a lot of memory.
What about my proposal, which was :
IntegerProto = $new(null);
IntegerProto.value = null; // allocate object slot
$objsetproto(IntegerProto,Integer);
Integer.new = function(num) {
var o = $new(IntegerProto);
o.value = num;
o;
}
You could also maybe allocate a few static integers for small ones :
iconsts = $amake(256);
var i = 0;
while( i < 256 ) {
var o = $new(IntegerProto);
o.value = i;
iconsts[i] = i;
}
Integer.new = function(num) {
var o = iconsts[num];
if( o == null ) {
o = $new(IntegerProto);
o.value = num;
}
o;
}
--
Neko : One VM to run them all
(http://nekovm.org)