Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created July 24, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fhernd/1cc8285728d1876626be to your computer and use it in GitHub Desktop.
Save Fhernd/1cc8285728d1876626be to your computer and use it in GitHub Desktop.
Rendimiento COALESCE y ISNULL en T-SQL.
-- OrtizOL - xCSw - http://ortizol.blogspot.com
DECLARE @i INT SET @i = 1
DECLARE @CPU INT SET @CPU = @@CPU_BUSY
DECLARE @TiempoInicio DATETIME SET @TiempoInicio = GETDATE()
WHILE @i <= 1000000
BEGIN
IF COALESCE('abc', 'def') = 'def'
PRINT 1
SET @i = @i + 1
END
PRINT 'COALESCE, sin argumentos NULL'
PRINT 'Tiempo total de CPU: ' + CONVERT(varchar, @@CPU_BUSY - @CPU)
PRINT 'Total en milisegundos: ' + CONVERT(varchar, DATEDIFF(ms, @TiempoInicio, GETDATE()))
PRINT ''
GO
DECLARE @i INT SET @i = 1
DECLARE @CPU INT SET @CPU = @@CPU_BUSY
DECLARE @TiempoInicio DATETIME SET @TiempoInicio = GETDATE()
WHILE @i <= 1000000
BEGIN
IF ISNULL('abc', 'def') = 'def'
PRINT 1
SET @i = @i + 1
END
PRINT 'ISNULL, sin argumentos NULL'
PRINT 'Tiempo total de CPU: ' + CONVERT(varchar, @@CPU_BUSY - @CPU)
PRINT 'Total en milisegundos: ' + CONVERT(varchar, DATEDIFF(ms, @TiempoInicio, GETDATE()))
PRINT ''
GO
DECLARE @i INT SET @i = 1
DECLARE @CPU INT SET @CPU = @@CPU_BUSY
DECLARE @TiempoInicio DATETIME SET @TiempoInicio = GETDATE()
WHILE @i <= 1000000
BEGIN
IF COALESCE(NULL, 'abc') = 'def'
PRINT 1
SET @i = @i + 1
END
PRINT 'COALESCE, primer argumento NULL'
PRINT 'Tiempo total de CPU: ' + CONVERT(varchar, @@CPU_BUSY - @CPU)
PRINT 'Total en milisegundos: ' + CONVERT(varchar, DATEDIFF(ms, @TiempoInicio, GETDATE()))
PRINT ''
GO
DECLARE @i INT SET @i = 1
DECLARE @CPU INT SET @CPU = @@CPU_BUSY
DECLARE @TiempoInicio DATETIME SET @TiempoInicio = GETDATE()
WHILE @i <= 1000000
BEGIN
IF COALESCE(NULL, 'abc') = 'def'
PRINT 1
SET @i = @i + 1
END
PRINT 'ISNULL, primer argumento NULL'
PRINT 'Tiempo total de CPU: ' + CONVERT(varchar, @@CPU_BUSY - @CPU)
PRINT 'Total en milisegundos: ' + CONVERT(varchar, DATEDIFF(ms, @TiempoInicio, GETDATE()))
PRINT ''
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment