Why curl > /dev/null and curl -o /dev/null has a large performance difference?
I can't reproduce this.
For that particular file, I did get slower speeds on some of the attempts, but that had nothing to do with the arguments to curl
, it happened randomly and with both variants.
The version of curl
I have (curl 7.52.1 (x86_64-pc-linux-gnu)
, from Debian), also doesn't handle /dev/null
any differently from other output files, strace
shows an open()
and write()
s to it:
$ strace -etrace=open,write curl -s http://www.google.com/ -o /dev/null
[...]
open("/dev/null", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 4
write(4, "<!doctype html><html itemscope=\""..., 4096) = 4096
write(4, "px 0 4px;margin-left:4px}input{f"..., 4096) = 4096
...
+++ exited with 0 +++
Here's an output for my last two runs, no significant difference between the > /dev/null
and -o /dev/null
:
$ curl http://dl.google.com/dl/android/aosp/sailfish-pq2a.190205.003-factory-164a7269.zip > /dev/null
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1344M 100 1344M 0 0 94.5M 0 0:00:14 0:00:14 --:--:-- 91.0M
$ curl http://dl.google.com/dl/android/aosp/sailfish-pq2a.190205.003-factory-164a7269.zip -o /dev/null
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1344M 100 1344M 0 0 89.3M 0 0:00:15 0:00:15 --:--:-- 92.8M
Steven Yang
Updated on September 18, 2022Comments
-
Steven Yang over 1 year
I am using Intel Atom D525, an extremely unpowerful processor for my family router with Debian 9. I tried both
curl http://dl.google.com/dl/android/aosp/sailfish-pq2a.190205.003-factory-164a7269.zip > dev/null
andcurl http://dl.google.com/dl/android/aosp/sailfish-pq2a.190205.003-factory-164a7269.zip -o dev/null
on that. The previous one can only get a speed of 25 MB/s and the next one can get a speed of 38 MB/s, mostly full of my 300Mbps bandwidth. Why these two command have such a gap of performance?-
ilkkachu over 5 yearsI do wonder a bit about the use-case here. Are you just measuring your network connection speed? Otherwise one would assume that it would be more interesting to look at how quickly you can download and process/store the file, than just download and throw away.
-
Steven Yang over 5 years@ilkkachu If I use wget, the speed is about 8 MB/s. With curl >, the speed is about 11 MB/s. With curl -o, the speed is about 14 MB/s.
-
-
Steven Yang over 5 yearsThere are also no differences for the two commands on my PC with Intel i7. But on devices with much slower CPU I can always reproduce this.