Golang:
package main
import (
"net/http"
"os"
"io"
)
func main() {
resp, _ := http.Get("http://www.sina.com.cn/")
defer resp.Body.Close()
io.Copy(os.Stdout, resp.Body)
}
Ruby:
require "net/http"
body = Net::HTTP.get(URI("http://www.sina.com.cn/"))
puts(body)
结果:
go build download.go
time ./download
./download 0.01s user 0.01s system 21% cpu 0.089 total
time go run download.go
go run download.go 0.85s user 0.09s system 124% cpu 0.756 total
time ruby download.rb
ruby download.rb 0.07s user 0.02s system 23% cpu 0.376 total
内存占用:
测试方法 ps -o rss -p `pid of process`
4140 KB ./download
9716 KB go run download.go
12908 KB ruby download.rb