[Tuning Tips] Hàm do thời gian C#, JAVA, SQL Server

Discussion in 'Tuning Tips' started by ocrenaka, Feb 26, 2013.

  1. Offline

    ocrenaka

    • Trùm Cuối

    Message Count:
    1,594
    Likes Received:
    464
    Trophy Points:
    83
    Mấy hàm này rất có ít trong việc Tuning khi ta cần kiểm tra thời gian thực thi của một đoạn code

    Java
    Code:
    long start_time = System.currentTimeMillis();
     
    //code inside
     
     
    //
     
    long end_time = System.currentTimeMillis();
    long execution_time = end_time - start_time;
    C#
    Code:
    Stopwatch objStopWatch = new Stopwatch();
    objStopWatch.Start();
    for (int i = 0; i < 1000000; i++)
    {
                   
                 
    }
    objStopWatch.Stop();
    Console.WriteLine(objStopWatch.ElapsedMilliseconds);
    SQL Server

    Code:
    DECLARE @StartTime DATETIME
    
    DBCC DROPCLEANBUFFERS  -- Force data/index pages out of buffer cache for valid test
    
    SET @StartTime = GETDATE() 
    
    -- Measurement Starts  
    
    
    
    -- Measurement Ends  
    
    SELECT ExecutionTimeInMS = DATEDIFF(millisecond, @StartTime, GETDATE())
    
    GO
    
    

Share This Page