{"id":21848909,"url":"https://github.com/hayatto9217/bench_web_server_v1.1","last_synced_at":"2026-04-29T23:02:27.542Z","repository":{"id":264877656,"uuid":"894511975","full_name":"Hayatto9217/bench_web_server_v1.1","owner":"Hayatto9217","description":"各言語でのベンチマークからわかる考察","archived":false,"fork":false,"pushed_at":"2024-11-27T02:51:18.000Z","size":4143,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-13T15:47:20.846Z","etag":null,"topics":["benchmark","deno","go","rust","zig"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Hayatto9217.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-26T13:39:30.000Z","updated_at":"2024-11-27T02:51:21.000Z","dependencies_parsed_at":"2024-11-26T16:22:46.533Z","dependency_job_id":"446e1f9a-9767-41f6-b93f-ce00cc2fb5fd","html_url":"https://github.com/Hayatto9217/bench_web_server_v1.1","commit_stats":null,"previous_names":["hayatto9217/bench_web_server_v1.1"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Hayatto9217/bench_web_server_v1.1","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hayatto9217%2Fbench_web_server_v1.1","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hayatto9217%2Fbench_web_server_v1.1/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hayatto9217%2Fbench_web_server_v1.1/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hayatto9217%2Fbench_web_server_v1.1/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Hayatto9217","download_url":"https://codeload.github.com/Hayatto9217/bench_web_server_v1.1/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hayatto9217%2Fbench_web_server_v1.1/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32447312,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-29T22:27:22.272Z","status":"ssl_error","status_checked_at":"2026-04-29T22:10:49.234Z","response_time":110,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["benchmark","deno","go","rust","zig"],"created_at":"2024-11-28T00:09:22.538Z","updated_at":"2026-04-29T23:02:27.514Z","avatar_url":"https://github.com/Hayatto9217.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"#  Deno, Go, Rust, Zig: A Benchmark 考察入り\n\n## Intro\n\nZig のOS自作中にふと気がついたのですが,Webでベンチマークするとどれぐらいの比較があるのか確認したくなりました。\n*ZigのVersionが変更されたことによって、標準ライブラリーが削除されているという...(先月修正したばかりなのに）\nStreamServerライブラリが削除されている.....\n\u003cimg width=\"1712\" alt=\"スクリーンショット 2024-11-27 10 26 57\" src=\"https://github.com/user-attachments/assets/a3d012a1-8871-4a4d-855f-9d5e0ae87cf9\"\u003e\n\n\n\n## ベンチマーク\n\n| Language | Requests per second     | Time per request  |\n| :------- | :---------------------- | :---------------- |\n| deno     | 32913.58 [#/sec] (mean) | 0.304 [ms] (mean) |\n| go       | 85736.82 [#/sec] (mean) | 0.117 [ms] (mean) |\n| node     | 11187.35 [#/sec] (mean) | 0.894 [ms] (mean) |\n| rust     | 20267.08 [#/sec] (mean) | 0.493 [ms] (mean) |\n| zig      | **測定不能**              | **測定不能**        |\n\nということで、**Go が一番速い**\n\n\n## **注意**\n\n**この計測は、特定の言語やフレームワークを批判するものではないので\nそれぞれの言語やフレームワークには、それぞれの良いところ、悪いところがあると思っていますのでご了承ください。\nまた、計測方法や各言語の最適化ができていないと思います。\n間違いがあったときは申し訳ございません。**\n\n## ベンチマークの実行\n\n### install(MacOSで検証)\n\n\n```sh\nbrew install httpd\n```\n\n### run\n\n```sh\nab -k -c 10 -n 100000 http://127.0.0.1:3000/\n```\n\n## ベンチマークのコード\n\n### Go\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"net/http\"\n)\n\nfunc main() {\n\thttp.HandleFunc(\"/\", func(w http.ResponseWriter, r *http.Request) {\n\t\tw.Header().Add(\"Content-Type\", \"text/html\")\n\t\tfmt.Fprintf(w, \"\u003ch1\u003eHello World\u003c/h1\u003e\")\n\t})\n\thttp.ListenAndServe(\":3000\", nil)\n}\n\n```\n\n### Rust\n\n```rust\nuse std::io::{Read, Write};\nuse std::net::{TcpListener, TcpStream};\nuse std::thread;\n\nfn main() {\n    let listener = TcpListener::bind(\"127.0.0.1:3000\").unwrap();\n    println!(\"Server running on 127.0.0.1:3000\");\n\n    for stream in listener.incoming() {\n        let stream = stream.unwrap();\n\n        thread::spawn(move || {\n            handle_connection(stream);\n        });\n    }\n}\n\nfn handle_connection(mut stream: TcpStream) {\n    let mut buffer = [0; 1024];\n\n    // request\n    if let Err(e) = stream.read(\u0026mut buffer) {\n        eprintln!(\"Failed to read from stream: {}\", e);\n        return;\n    }\n\n    // HTTPレスポンス\n    let response = b\"HTTP/1.1 200 OK\\r\\n\\r\\n\u003ch1\u003eHello World\u003c/h1\u003e\";\n\n    if let Err(e) = stream.write(response) {\n        eprintln!(\"Failed to write to stream: {}\", e);\n        return;\n    }\n\n    if let Err(e) = stream.flush() {\n        eprintln!(\"Failed to flush stream: {}\", e);\n        return;\n    }\n}\n\n```\n\n### Zig\n\n```zig\nconst std = @import(\"std\");\nconst net = std.net;\nconst StreamServer = net.StreamServer;\nconst Address = net.Address;\npub const io_mode = .evented;\n\npub fn main() anyerror!void {\n  var stream_server = StreamServer.init(.{});\n  defer stream_server.close();\n  const address = try Address.resolveIp(\"127.0.0.1\", 3000);\n  try stream_server.listen(address);\n  while (true) {\n    const client = try stream_server.accept();\n      const response = \"HTTP/1.1 200 OK\\r\\n\\r\\n\u003ch1\u003eHello World\u003c/h1\u003e\";\n      try client.write(response);\n    }\n}\n\n```\n\n### Deno\n\n```ts\nconst server = Deno.listen({ port: 3000 });\n\nfor await (const conn of server) {\n  serveHttp(conn);\n}\n\nasync function serveHttp(conn: Deno.Conn) {\n  const httpConn = Deno.serveHttp(conn);\n  for await (const requestEvent of httpConn) {\n    const body = \"\u003ch1\u003eHello World\u003c/h1\u003e\";\n    requestEvent.respondWith(\n      new Response(body, {\n        status: 200,\n      })\n    );\n  }\n}\n```\n\n### Makefile\n\n```makefile\n.phony:\n\nbuild-go:\n\tgo build go/main.go \u0026\u0026 ./main\n\nbuild-rust:\n\trustc rust/main.rs \u0026\u0026 ./main\n\nbuild-zig:\n\tzig build-exe zig/main.zig \u0026\u0026 ./main\n\nrun-go:\n\tgo run go/main.go\n\nrun-deno:\n\tdeno run --allow-net deno/main.ts\n\nbench:\n\tab -k -c 10 -n 10000 http://127.0.0.1:3000/\n\nbench-go:\n\tab -k -c 10 -n 10000 http://127.0.0.1:3000/ \u003e bench/go.txt\n\nbench-rust:\n\tab -k -c 10 -n 10000 http://127.0.0.1:3000/ \u003e bench/rust.txt\n\nbench-deno:\n\tab -k -c 10 -n 10000 http://127.0.0.1:3000/ \u003e bench/deno.txt\n\nbench-zig:\n\tab -k -c 10 -n 10000 http://127.0.0.1:3000/ \u003e bench/zig.txt\n\ncheck-port:\n\techo 'sudo lsof -i :3000'\n\nstop apachectl stop command\n         'sudo apachectl stop'\n\n```\n\n\n## 考察\n各処理系のバージョンを明記しておいて他の方が同じ条件で追試を行うことが重要かと思った。\n\nabだと遅いので、他のベンチマークツールがあると教えていただきたいです。\n\nそもそもベンチマークまとめたリポジトリとかってあるのかな...\n\n自分が知る限りはShell自作するとかしてやりたいところ\n\n試したいリスト\nhttps://github.com/codesenberg/bombardier\n\nbunもやってみるといいのかもしれない\nDenoも'Deno.serve'を使うと速いかなと思ったりして。\n\n\n###### 雑談 \n\nRust の場合ですが、そもそも TCPListener でのシングルスレッド処理なので遅いのは仕方ないのかなという気持ちです。非同期処理したいなら、パッケージ入れるしかないかなと...\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhayatto9217%2Fbench_web_server_v1.1","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhayatto9217%2Fbench_web_server_v1.1","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhayatto9217%2Fbench_web_server_v1.1/lists"}