SQL Server 2008 Spatial - Which is faster WKT or WKB?
I've just posted two methods for creating geometries in
client code. The examples use Stylus points from an ink canvas but any
collection of points will go.
After doing that I ran some tests to compare the two.
I found that in generally the WKB method was ~70% faster to build the WKB and
40% faster to parse the WKB to generate the SqlGeometry instance.
In some cases i.e large numbers of points, WKB was 95% faster to build the
WKB and 90% faster to parse.
I thought it could be the string array, but even with the a stringbuilder the
performance was similar.
In the test I was using the ink canvas which generates decimal points, this
means the string representations are large. I would suspect that if using small
integer points the difference wouldn't be as much.
If you want to know the reason you can download a copy of reflector and look
at the SqlServer.Types.dll. You will then see that the WKT parser has to find
the boundaries of the points (spaces, commas and brackets). The WKB does as a
float is stored as 8 bytes and so the parser just reads eight bytes to get the X
and then another 8 to get the Y etc.
-