Skip to content

Instantly share code, notes, and snippets.

@smetj
Created October 22, 2012 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smetj/3935398 to your computer and use it in GitHub Desktop.
Save smetj/3935398 to your computer and use it in GitHub Desktop.
Compare speed between "piping stdout over nc" or "write directly" to a remote server.
https://github.com/smetj/experiments/blob/master/python/testlap/stdout_vs_socket.py
[smetj@indigo python]$ python compare_stdout_socket.py 2> >(nc -w1 -u localhost 10000)
Running test_1
OK
Running test_2
OK
2.7.3 (default, Jul 24 2012, 10:05:38)
[GCC 4.7.0 20120507 (Red Hat 4.7.0-5)]
Linux-3.6.2-4.fc17.x86_64-x86_64-with-fedora-17-Beefy_Miracle
Compare speed of writing data to a remote UDP listener using 2 different methods:
* Write to stdout/stderr and pipe to remote listener using netcat
* Write directly to the remote listener
Start in another shell a listening UDP server which writes data to /dev/null:
$ nc -klu localhost 10000 > /dev/null
Start this script by redirecting STDERR to a nc process:
$ python compare_stdout_socket.py 2> >(nc -w1 -u localhost 10000)
+----------+----------------------------------------------------------------------------------------+--------+---------------+
| Function | Description | Result | Seconds |
+----------+----------------------------------------------------------------------------------------+--------+---------------+
| test_2 | Write directly to a remote socket. | OK | 17.650318861 |
| test_1 | Write to STDERR so we can redirect this output and keep the TestLap summary on STDOUT. | OK | 39.4371290207 |
+----------+----------------------------------------------------------------------------------------+--------+---------------+
[smetj@indigo python]$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment