DATEFROMPARTS vs ‘19000101’

le DateFromParts est plus performant  

DECLARE @compteur INT;
DECLARE @date DATETIME;
DECLARE @dStart DATETIME;
DECLARE @msString INT = 0;
DECLARE @msdate INT = 0;
DECLARE @msfunc INT = 0;
SET @dStart = GETDATE();
DECLARE @boucle INT;
SET @boucle = 1;
WHILE @boucle < 10
BEGIN

    SET @compteur = 1;
    WHILE @compteur < 10000
    BEGIN
        SET @Date = '19000101';
        SET @compteur = @compteur + 1;
    END;
    SET @msString = @msString + DATEDIFF(ms, @dStart, GETDATE());
    SET @dStart = GETDATE();
    SET @compteur = 1;
    WHILE @compteur < 10000
    BEGIN
        SET @Date = Datefromparts(1900,01,01)
        SET @compteur = @compteur + 1;
    END;
    SET @msdate = @msdate + DATEDIFF(ms, @dStart, GETDATE());
    SET @boucle = @boucle + 1;
END;
PRINT 'String ' + LEFT(@msString, 20) + ' ms ';
PRINT 'Date ' + LEFT(@msdate, 20) + ' ms ';

Votre commentaire

Entrez vos coordonnées ci-dessous ou cliquez sur une icône pour vous connecter:

Logo WordPress.com

Vous commentez à l’aide de votre compte WordPress.com. Déconnexion /  Changer )

Photo Facebook

Vous commentez à l’aide de votre compte Facebook. Déconnexion /  Changer )

Connexion à %s