if object_id(N'dbo.PerformanceMarker') is not null drop procedure dbo.PerformanceMarker go /*============================================================================== SAMPLE USAGE declare @prevTime datetime = getdate() -- Do something here exec dbo.PerformanceMarker 'Doing something', @prevTime out -- Do something else here exec dbo.PerformanceMarker 'Doing something else', @prevTime out SAMPLE OUTPUT (73 row(s) affected) Doing something took 0.023 second(s) (177874 row(s) affected) Doing something else took 2.210 second(s) ==============================================================================*/ create procedure dbo.PerformanceMarker ( @stage varchar(100) ,@prevTime datetime OUT ) as declare @currTime datetime = getdate() declare @elap int = datediff(ms, @prevTime, @currTime) declare @frac varchar(3) = convert(varchar(3), @elap % 1000) set @frac = right('000' + @frac, 3) print @stage + ' took ' + convert(varchar(20), @elap / 1000) + '.' + @frac + ' second(s)' set @prevTime = @currTime