全能空間中asp.net/php/asp那種效能更好測試分析

來源:互聯網
上載者:User

下面是本人今天的測試記錄。

      測試裝置及環境
      測試裝置:自用筆記本
      測試系統:Windows Server 2003企業版
      運行環境:IIS6.0
      測試方法
      分別用asp.net、php和asp執行一千萬次for迴圈,獲得執行時間。如下為測試代碼:
      asp.net
   
 代碼如下 複製代碼
     System.DateTime startTime = System.DateTime.Now;
        for (long i = 1; i < 10000000; i++)
        {
        }
        System.DateTime endTime = System.DateTime.Now;
        System.TimeSpan ts = endTime - startTime;
        Response.Write("頁面執行時間:" + ts.Milliseconds.ToString("0.000") + " 毫秒");
      php
       
 代碼如下 複製代碼
<?php
        $start_time=microtime(true);
        for($i=0; $i<10000000; $i++)
        {
        }
        $end_time=microtime(true);
        print "頁面執行時間: ".round(($end_time-$start_time)*1000,1)." 毫秒";
        ?>
     
asp
       
 代碼如下 複製代碼
<%
        dim i
        dim startime
        startime=timer()
        for i = 1 to 10000000
        next
        dim endtime
        endtime=timer()
        response.Write "頁面執行時間:" & FormatNumber((endtime-startime)*1000,3) & "毫秒"
        %>
     
執行結果
      為了得到更合理的資料,採用各執行5次(第一次執行除外),然後取平均值。如下為測試結果:
語言 執行時間 平均時間
asp.net 31ms 15ms 31ms 15ms 15ms 21ms
php 1470ms 1473ms 1476ms 1467ms 1490ms 1475ms
asp 812ms 828ms 812ms 812ms 828ms 818ms
      從以上測試結果看出,asp.net的執行時間比php快了70倍,比asp快了39倍。這個測試結果是我一直沒有想到的。
      系統資源消耗情況
      下面是執行各程式時的系統資源消耗情況,主要是看cpu和記憶體瞬間值。
      asp.net
      asp.net執行程式時cpu峰值升到10%,使用記憶體顯示是1.01GB(注意,測試時筆記本並沒有關閉其他所有運行著的程式,所以這個記憶體並不是此程式執行單獨消耗的數值)。
      php
      php執行程式時cpu峰值升到75%,使用記憶體顯示是1.03GB。
      asp
      asp執行程式時cpu峰值升到58%,使用記憶體顯示是1.06GB。
      總結:在系統資源消耗方面,asp.net的優勢再次凸顯出來了,它對cpu的消耗比php和asp少很多,php對cpu的消耗比asp多一點,但差別不大;而對記憶體的消耗,三者差別並不大。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.