• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Go语言和ASP.NET的一般处理程序在处理WEB请求时的速度比较

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

1、首先写一个Go语言的简单WEB程序,就返回一个HelloWord!

package main

import (
    f "fmt"
    "log"
    "net/http"
    //    "strings"
)

func sayhelloName(w http.ResponseWriter, r *http.Request) {
    //    r.ParseForm()
    //    f.Println(r.Form)
    //    f.Println("path", r.URL.Path)
    //    f.Println("scheme", r.URL.Scheme)
    //    f.Println(r.Form["url_long"])
    //    for k, v := range r.Form {
    //        f.Println("key:", k, "val:", strings.Join(v, "、"))
    //    }

    f.Fprintln(w, "hello world!")
}
func main() {
    http.HandleFunc("/", sayhelloName)
    err := http.ListenAndServe(":8080", nil)
    if err != nil {
        log.Fatal("ListenAndServe:", err)
    }
}

 

 

2、建一个Asp.net的Handler1.ashx的一般处理程序,并运行于IIS中。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace TESTWeb
{
    /// <summary>
    /// Handler1 的摘要说明
    /// </summary>
    public class Handler1 : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.Write("hello world!");
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

 

 

3、用C#写一个控制台程序,用来模拟发起10000次请求时,速度比较:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;

namespace TESTSpeed
{
    class Program
    {
        static void Main(string[] args)
        {
      
            WebClient wc = new WebClient();
            DateTime dt1 = DateTime.Now;
            for (int i = 0; i < 10000; i++)
            {
                var result = wc.DownloadString("http://localhost:48563/handler1.ashx?t=" + DateTime.Now.Ticks);
            }
            DateTime dt2 = DateTime.Now;
            Console.WriteLine("Asp.net一般处理程序用时:" + (dt2 - dt1).TotalMilliseconds);

            WebClient wc2 = new WebClient();
            DateTime dt3 = DateTime.Now;
            for (int i = 0; i < 10000; i++)
            {
                var result = wc2.DownloadString("http://127.0.0.1:8080/?t=" + DateTime.Now.Ticks);
            }
            DateTime dt4 = DateTime.Now;
            Console.WriteLine("Go语言用时:" + (dt4 - dt3).TotalMilliseconds);
        }
    }
}

 

4、测试结果:

Go语言用时:811.0464ms

Asp.net一般处理程序:14017.8017ms

5、结论:Go不是一般的快!!!!相差了17倍!!!

 

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Go interface发布时间:2022-07-10
下一篇:
go依赖包下载加速方法及github加速发布时间:2022-07-10
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap