[Mono-dev] Removing unsafe code in BitConverter and speedups

Alan McGovern alan.mcgovern at gmail.com
Sat May 10 18:06:51 EDT 2008


I did some work on BitConverter.cs which accomplishes the following:

1) Removed all unsafe code, everything is managed now
2) Improved performance of DoubleToInt64Bits and Int64BitsToDouble
pretty significantly, about 2.5x faster. I'd say this is mostly
because this implementation doesn't create an intermediate array when
performing the conversion.
3) Small speed increase to the GetBytes() overloads (1-4%)
4) ToInt16 and ToInt32 takes a 30% and 25% speed hit respectively.
ToInt64 is 7% slower.

I've tested the changes and they pass all the NUnit tests. If someone
on a big endian or middle endian system can test the changes to ensure
that there isn't some hidden gotcha that i didn't notice, that'd be

BitConverter.cs and Main.cs can be compiled together and run as the
testbench program. To testbench different bitconverter methods, just
edit Main.cs and change the method that is called in the loop.

Finally, is this patch worth committing?

-------------- next part --------------
A non-text attachment was scrubbed...
Name: bitconverter.patch
Type: text/x-patch
Size: 14878 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20080510/a239daa0/attachment-0003.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bitconverter.cs
Type: text/x-csharp
Size: 14302 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20080510/a239daa0/attachment-0004.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Main.cs
Type: text/x-csharp
Size: 658 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20080510/a239daa0/attachment-0005.bin 

More information about the Mono-devel-list mailing list