【问题标题】:Benchmarking curl vs wget vs python-request library基准测试 curl vs wget vs python-request 库
【发布时间】:2020-02-24 00:26:02
【问题描述】:

我正在处理 WebGoat 上的一些挑战,我需要对服务器进行暴力请求攻击。我在 bash 中编写了一个脚本(使用 curl)。但是,我在网上找到了一个类似的用python编写的脚本,当我运行它时,python脚本能够以更快的速度运行攻击。

因此,我想出了一个小的基准测试实验。我将使用以下脚本向该容器发出请求,并使用time 对性能进行基准测试。

$ cat test_curl
#!/usr/bin/env bash
for i in {1..1000}; do
    curl -s -o /dev/null 'http://localhost:8080/WebGoat/login'
done
$ cat test_wget
#!/usr/bin/env bash
for i in {1..1000}; do
    wget -q -O /dev/null 'http://localhost:8080/WebGoat/login'
done
$ cat test_request
#!/usr/bin/env python3
import requests

for i in range(1, 1001):
    requests.get('http://localhost:8080/WebGoat/login')
$ time ./test_request
real    0m4.240s
user    0m2.136s
sys     0m0.125s
$ time ./test_wget
real    0m4.623s
user    0m1.752s
sys     0m0.731s
$ time ./test_curl
real    0m17.907s
user    0m7.420s
sys     0m3.692s

总之,当我提出大量请求时,我是否应该避免使用curl?似乎python-requests 在这里脱颖而出。有人可以验证我的结论吗?我错过了什么吗?

有人知道curlwget 在性能上的巨大差异吗? 似乎几年前在curlwget here 之间进行了类似的实验。但在性能上仍然存在明显差异。

【问题讨论】:

    标签: curl python-requests wget


    【解决方案1】:

    奇怪的是,python 在你的机器上比 curl 快。 在我的 macbook pro 上:

    time ./test_curl
    ./test_curl  15.78s user 8.04s system 39% cpu 1:00.09 total
    time ./test_request
    ./test_request  39.26s user 2.58s system 10% cpu 6:29.79 total
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-11-27
      • 1970-01-01
      • 2014-10-09
      • 2012-03-13
      • 2020-07-04
      • 2013-06-29
      • 1970-01-01
      相关资源
      最近更新 更多