<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">David might have other ideas, but I suspect what is happening is that Self isn't cheating enough.<div><br></div><div>Multiply two bigInts in Self and the maths primitives are still at the smallInt level, with lots of Self level code to chop the bigInts into smallInts and then reassemble them.</div><div><br></div><div>Look at the code to multiply a bigInt by another and you soon end up with stuff like:</div><div><br></div><div><div>mulDigits: digits1 And: digits2 = ( | carryIdx <- 0. carryM <- 0. dsize1 <- 0. dsize2 <- 0. res |</div><div>    dsize1: digits1 size.</div><div>    dsize2: digits2 size.</div><div>    carryIdx: dsize2 - cByteSize.</div><div>    res: (digitsRep copySize: dsize1 + dsize2 FillingWith: 0).</div><div>    0 upTo: dsize1 By: cByteSize Do: [</div><div>        |:idx1. carryA <- 0. | </div><div>        carryM: (mulOne: (in: digits1 At: idx1)</div><div>                Digits: digits2</div><div>          ResultStream: [|:x. :idx2. idx <- 0. y <- 0. c <- 0. | </div><div>            idx: idx1 + idx2.</div><div>            idx2 = carryIdx ifTrue: [</div><div>                "Last digit in 'digits2' so use left over carry</div><div>                 from last round."</div><div>                c: carryM.</div><div>            ].</div><div>            y: c + x + (in: res At: idx) + carryA.</div><div>            base <= y ifTrue: [carryA: 1. y: y - base] </div><div>                       False: [carryA: 0].</div><div>            in: res At: idx Put: y.</div><div>        ]).</div><div>        carryM: carryM + carryA.</div><div>    ].</div><div>    "Finish off with carry."</div><div>    assert: [0 = (mostSignificantDigit: res)].</div><div>    in: res At: res size - cByteSize Put: carryM.</div><div>    res)</div></div><div><br></div><div>I'm not surprised the JIT can't get us there!</div><div><br></div><div>Presumably we need specific bignum primitives to call as soon as the original small integer gets promoted to a larger one.</div><div><br></div><div>Russell</div><div><br><div><div>On 14/09/2013, at 11:49 PM, Chris Double <<a href="mailto:chris.double@double.co.nz">chris.double@double.co.nz</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">













<div style="background-color: #fff;">
<span style="display:none"> </span>



    <div id="ygrp-text"><p>Bignum performance in Self seems to be quite slow. Executing 1000<br>
factorial on my laptop gives the following:<br>
<br>
[ 1000 factorial ] time<br>
   => 2228<br>
<br>
On similar JIT'd languages that support bignums I get subsecond<br>
results. Implementing similar to factorial to use '+' instead of '*' to<br>
ensure that no bignums are created I get:<br>
<br>
[ 1000 foo ] time<br>
   => 0<br>
<br>
Where 'foo' is a method on 'traits integer':<br>
<br>
<= 1 ifTrue: 1 False: [ + predecessor foo ]<br>
<br>
Has anyone got ideas on what the performance hit might be caused by?<br>
<br>
Chris.<br>
-- <br>
<a href="http://www.bluishcoder.co.nz">http://www.bluishcoder.co.nz</a><br>
</p>

    </div>
     

    

</div>



<!-- end group email -->

</blockquote></div><br></div></body></html>