Numeric access to char[]
Chad J
gamerChad at _spamIsBad_gmail.com
Fri Aug 25 01:59:09 PDT 2006
nobody wrote:
> Chad J wrote:
>
>> nobody wrote:
>> ....
>>
>>>
>>> So you will have to do it manually. I would like to suggest that if
>>> you can pad the char[] to ensure its .length % 8 == 0 then you can
>>> cast it to a ulong and your shifting will be faster.
>>
>>
>> Sure about ulong? In my spare time I made my own minimal Bignum
>> implementation. I'm not sure about shifts, but for addition with
>> carrying it was faster to use size_t (uint in this case) rather than
>> ulong. I wonder if maybe the compiler could optimize it better if it
>> didn't have to emulate 64 bit integers. Or my benchmark was borked.
>
>
> I certainly could be wrong but I would be quite surprised. I would be
> interested to see what tests you ran that suggest addition with carry
> was faster.
This BigNum I made is very incomplete and probably slow. Changing the
size of it's digits shouldn't do anything besides just that, though.
I have attached 2 .d files, BigNum.d is the implementation, main.d is
the benchmark. I compiled it with dmd -O -inline -release. At the top
of BigNum.d there is an alias that I use to switch between size_t and
ulong variables used in the computation.
Here are my results. See main.d for details of the setup.
Microseconds to complete 1000000 additions using size_t:
786779
776801
793653
783896
787937
789150
Microseconds to complete 1000000 additions using ulong:
866767
860499
866921
865791
860874
858154
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: main.d
Url: http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20060825/0c0da3cd/attachment.diff
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: BigNum.d
Url: http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20060825/0c0da3cd/attachment-0001.diff
More information about the Digitalmars-d-learn
mailing list