Call now: (800) 766-1884  



 Home


 SQL Server Tips
 SQL Server Training

 SQL Server Consulting
 SQL Server Support
 SQL Server Remote DBA



 Articles
 Services
 SQL Server Scripts
 Scripts Menu



 

 

 

   
  SQL Server Tips by Gama and Naughter

Comparing several MD5 implementations

This is a collection of tests based on the excellent code of Robert M. Hubley. His code is posted on:

http://www.freevbcode.com/ShowCode.Asp?ID=741

Robert ported the MD5 algorithm to a VB Native Class, a C DLL (with a VB wrapper), and a Java port. From the VB Class it is easy to create an ActiveX DLL that can be called from TSQL with the sp_oa* procedures or with XP_RUNSCRIPT. Another interesting test is to turn the VB code into VBScript and call it with XP_RUNSCRIPT or turn it into VB.NET for tests on SQL Server 2005.

MD5 algorithm in different flavors, tested with 10,000 rows against SQL Server 2005

Execution time

Implementation Object name Time (seconds) XP using Microsoft Crypto API XP_MD5_HASH 6.9 XP using MD5 C++ class XP_MD5 2.5 ActiveX DLL (VB6) using sp_oa* procedures n/a 52 ActiveX DLL (VB6) using XP_RUNSCRIPT MD5.js 64 VBScript using XP_RUNSCRIPT MD5.vbs 9500+ VB.NET Stored Procedure spMD5VB 3.2 Table 23.3 time comparison

What is quite interesting is that the native mode Crypto API implementation is slower than the .NET implementation. This may be due to the overheard required to load and initialize the CSP infrastructure, which is part of the MS Crypto API. Also, the purely interpreted implementation using VBScript and XP_RUNSCRIPT behaves very badly and would not be very useful in real-world situations. The fastest implementation is the XP implementation in pure C++. It is 16% faster than the VB .NET implementation. The middle ground is where we use the sp_oa* functions to call into a COM object. You can see that there is quite an overhead to using this approach compared with the more direct integration, which can be achieved using an XP or a .NET assembly. You might be able to achieve better performance if you were to write a C++ COM object using ATL instead of Visual Basic 6, but your effort might be better spent developing an XP version (i.e. XP_MD5) if your main target is SQL Server instead of any COM enabled development environment. If you were only targeting SQL Server 2005, then .NET would also be a good choice in this particular scenario. Also note that the XP_RUNSCRIPT implementation that calls the COM object is only marginally slower than sp_OACreate. The non .NET based tests when run against SQL Server 2000 return a broadly similar breakdown of results. Please bear in mind that these figures are based on tests on a beta release of SQL Server 2005. The ratios may change somewhat when SQL Server 2005 is released, but you would still expect the same broad breakdown of results. Also remember than these benchmarks are only applicable to our testing of a purely calculation bound cryptographic hash function. If your code is doing a combination of things, then you will not see the wildly divergent figures, which this benchmark demonstrates.


The above book excerpt is from:

Super SQL Server Systems
Turbocharge Database Performance with C++ External Procedures

ISBN: 0-9761573-2-2
Joseph Gama, P. J. Naughter

 http://www.rampant-books.com/book_2005_2_sql_server_external_procedures.htm
 

 

Burleson Consulting Remote DB Administration


 

 


 

 

 

 

 
Burleson is the America's Team

Note: The pages on this site were created as a support and training reference for use by our staff of DBA consultants.  If you find it confusing, please exit this page.

Errata?  SQL Server technology is changing and we strive to update our SQL Server support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:and include the URL for the page.
 


Burleson Consulting
SQL Server database support

 

Copyright 1996 -  2013 by Vaaltech Web Services. All rights reserved.

Hit Counter