In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you Python and Go language requests per second comparison example analysis, I believe that most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!
I wrote a simple REST service in different languages and used the ab tool to test the response speed.
Python
Server.py
From bottle import route, run @ route ('/') def home (): article = {'name':' A Royal Baby', 'body':'A slow news week'} return article def main (): run (host='localhost', port=8081) if _ _ name__ = =' _ main__': main ()
Go
Server.go
Package main import ("encoding/json"fmt"github.com/emicklei/go-restful"io"net/http") func main () {ws: = new (restful.WebService) ws.Route (ws.GET ("/") .to (hello)) restful.Add (ws) fmt.Print ("Server starting on port 8080\ n") http.ListenAndServe (": 8080") Nil)} func hello (req * restful.Request, resp * restful.Response) {article: = Article {"A Royal Baby", "A slow news week"} b, _: = json.Marshal (article) io.WriteString (resp, string (b))} type Article struct {Name string Body string}
The Go version is obviously more detailed than the Python version, but I think it's still very concise. The Python server uses the bottle framework and the specified article dictionary is automatically serialized back as a response. The Go server uses the go-restful package, which makes it easy to build RESTful API in Go.
The benchmark is CPU i7 2.4 GHz RAM 16GB on Macbook Pro.
Use the following command:
Ab-Q-c 50-n 1000 http://127.0.0.1:8080/ | grep "Requests per second"
Result
5 tests, average number of requests completed per second for 1000 requests
RunPythonGo11310.5813568.3421332.8213092.9531331.5413479.4541306.0913271.5851274.4913873.09
Go completes an average of 13457 requests per second, while Python completes 1311 requests per second
In this test, Go is 10.26 times faster than Python in completing the JSON response.
The above is all the contents of the article "sample Analysis of the comparison of requests per second between Python and Go". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.