2025年再來測試一下.NET各個版本和Golang&Rust的web性能,哪個更快?
今天無聊又翻出了一篇很久以前golang和.net測試的文章(原文),
很是好奇7、8年過去了,golang和.net 有啥變化嗎?
于是我在電腦上又測了一遍。
我的電腦是win10系統(tǒng),.net sdk都下了最新的版本,重新安裝了一編,golang用的是go1.24.1。
添加了rust 的actix-web和may_minihttp。為啥是may_minihttp?因為在techempower第23輪測試中may_minihttp排第一。
techempower第23輪:

好了,各位大佬來看看測試結(jié)果吧
.NET個版本測試結(jié)果:

gin和iris框架測試結(jié)果:

actix-web和may_minihttp框架測試結(jié)果:

- 完成
5000000 個請求的時間 - 越短越好。 - 請求次數(shù)/每秒 - 越大越好。
- 等待時間?—?越短越好。
- 內(nèi)存使用?—?越小越好。
- 吞吐量?—?越大越好。
.NET 代碼:
NET5.0、6.0、7.0:
using Microsoft.AspNetCore.Mvc;
namespace _5.Controllers
{
// ValuesController is the equivalent
// `ValuesController` of the Iris 8.3 mvc application.
[Route("api/[controller]")]
public class ValuesController : ControllerBase
{
// Get handles "GET" requests to "api/values/{id}".
[HttpGet("{id}")]
public string Get(int id)
{
return "value";
}
// Put handles "PUT" requests to "api/values/{id}".
[HttpPut("{id}")]
public void Put(int id, [FromBody] string value)
{
}
// Delete handles "DELETE" requests to "api/values/{id}".
[HttpDelete("{id}")]
public void Delete(int id)
{
}
}
}
NET8.0、9.0、10.0:
app.MapGet("/api/values/{id}", (int id) =>
{
return "value";
})
.WithName("GetApi")
.WithOpenApi();
Gin 代碼:
package main
import (
"github.com/gin-gonic/gin"
"io/ioutil"
)
func main() {
gin.SetMode(gin.ReleaseMode)
gin.DefaultWriter = ioutil.Discard
r := gin.Default()
r.GET("/api/values/:id", func(c *gin.Context) {
c.String(200, "value")
})
r.Run() // 監(jiān)聽并在 0.0.0.0:8080 上啟動服務(wù)
}
iris 代碼:
package main
import "github.com/kataras/iris/v12"
func main() {
app := iris.New()
booksAPI := app.Party("/api")
{
booksAPI.Use(iris.Compression)
booksAPI.Get("/values/{id}", Get)
}
app.Listen(":8080")
}
func Get(ctx iris.Context) {
// id,_ := vc.Params.GetInt("id")
ctx.WriteString("value")
}
may_minihttp 代碼:
use std::io;
use may_minihttp::{HttpServer, HttpService, Request, Response};
use may::coroutine;
#[derive(Clone)]
struct HelloWorld;
impl HttpService for HelloWorld {
fn call(&mut self, _req: Request, res: &mut Response) -> io::Result<()> {
match _req.path() {
"/api/values" => {
res.body("Hello, world!");
}
_ => {
res.status_code(404, "Not Found");
}
}
Ok(())
}
}
// 在 `main` 函數(shù)中啟動服務(wù)器。
fn main() {
// 配置 may 協(xié)程池
may::config()
.set_workers(8) // 設(shè)置線程數(shù)
.set_pool_capacity(500) // 設(shè)置協(xié)程池容量
.set_stack_size(0x1000); // 設(shè)置協(xié)程棧大小
let server = HttpServer(HelloWorld).start("0.0.0.0:8080").unwrap();
println!("Server running at http://127.0.0.1:8080");
server.join().unwrap();
}
actix-web代碼:
use actix_web::{web, App, HttpRequest, HttpServer, Responder};
async fn greet(req: HttpRequest) -> impl Responder {
let name = req.match_info().get("name").unwrap_or("World");
format!("Hello {}!", &name)
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new()
.route("/", web::get().to(greet))
.route("/api/values/{name}", web::get().to(greet))
})
.bind("127.0.0.1:8080")?
.run()
.await
}
電腦配置:
-
CPU:7840H
-
內(nèi)存:32.0 GB
-
網(wǎng)卡:AX210
-
操作系統(tǒng): Windows 10 22H2 專業(yè)版
參考地址:
https://linux.cn/article-8935-1-rel.html
https://hackernoon.com/go-vs-net-core-in-terms-of-http-performance-7535a61b67b8

浙公網(wǎng)安備 33010602011771號