there seems to be some overhead between SQL Server 2005 and a CLR function written in C#. Why is thi

there seems to be some overhead between SQL Server 2005 and a CLR function written in C#. Why is thi

am 27.10.2007 06:24:54 von DR

there seems to be some overhead between SQL Server 2005 and a CLR function
written in C#. Why is this?

I have a simple wraper around System.Diagnostics.Stopwatch.GetTimestamp() :

public partial class UserDefinedFunctions
{
[Microsoft.SqlServer.Server.SqlFunction]
public static long GetTimestampF()
{
return System.Diagnostics.Stopwatch.GetTimestamp();
}
};


but if i run this it is hardly accurate. the time of getting from sql server
to a CLR function seems to be relatively slow for nanosecond calculations:

DECLARE @before bigint
DECLARE @after bigint
SET @before = dbo.GetTimestampF()
-- do something
SET @after = dbo.GetTimestampF()
SELECT @after - @before as nanoseconds

is there nyway to elimitate this overhead so that dbo.GetTimestampF()
executes as fast for TSQL as it is to call GetTimestampF() in C#?

If i call my GetTimestampF() on c# it executes fast enough for the
nanosecond results to be accurate

Re: there seems to be some overhead between SQL Server 2005 and a CLR function written in C#. Why is

am 27.10.2007 22:29:13 von Anthony Jones

"DR" wrote in message
news:e%23UalFFGIHA.1208@TK2MSFTNGP05.phx.gbl...
> there seems to be some overhead between SQL Server 2005 and a CLR function
> written in C#. Why is this?
>
> I have a simple wraper around System.Diagnostics.Stopwatch.GetTimestamp()
:
>
> public partial class UserDefinedFunctions
> {
> [Microsoft.SqlServer.Server.SqlFunction]
> public static long GetTimestampF()
> {
> return System.Diagnostics.Stopwatch.GetTimestamp();
> }
> };
>
>
> but if i run this it is hardly accurate. the time of getting from sql
server
> to a CLR function seems to be relatively slow for nanosecond calculations:
>
> DECLARE @before bigint
> DECLARE @after bigint
> SET @before = dbo.GetTimestampF()
> -- do something
> SET @after = dbo.GetTimestampF()
> SELECT @after - @before as nanoseconds
>
> is there nyway to elimitate this overhead so that dbo.GetTimestampF()
> executes as fast for TSQL as it is to call GetTimestampF() in C#?
>

No. TSQL does not compile to native code. Why on earth would you need
this?!!


--
Anthony Jones - MVP ASP/ASP.NET