tyrion

sort lines python vs bash

Oct 16th, 2013
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. tyrion@aws:~/src/bash$ cat sort.sh
  2. sort < $1 > $2
  3. tyrion@aws:~/src/bash$ cat sort1.py
  4. import sys
  5.  
  6. inp = open(sys.argv[1], 'r')
  7. out = open(sys.argv[2], 'w')
  8.  
  9. out.writelines(sorted(inp))
  10. tyrion@aws:~/src/bash$ time sh sort.sh input.txt out.txt
  11.  
  12. real 0m0.065s
  13. user 0m0.032s
  14. sys 0m0.032s
  15. tyrion@aws:~/src/bash$ rm out.txt
  16. tyrion@aws:~/src/bash$ time sh sort.sh input.txt out.txt
  17.  
  18. real 0m0.011s
  19. user 0m0.000s
  20. sys 0m0.008s
  21. tyrion@aws:~/src/bash$ rm out.txt
  22. tyrion@aws:~/src/bash$ time sh sort.sh input.txt out.txt
  23.  
  24. real 0m0.011s
  25. user 0m0.004s
  26. sys 0m0.004s
  27. tyrion@aws:~/src/bash$ rm out.txt
  28. tyrion@aws:~/src/bash$ time python -S sort1.py input.txt out.txt
  29.  
  30. real 0m0.015s
  31. user 0m0.004s
  32. sys 0m0.008s
  33. tyrion@aws:~/src/bash$ rm out.txt
  34. tyrion@aws:~/src/bash$ time python -S sort1.py input.txt out.txt
  35.  
  36. real 0m0.014s
  37. user 0m0.000s
  38. sys 0m0.012s
  39.  
  40. # Without the -S performances are worse
  41.  
  42. tyrion@aws:~/src/bash$ rm out.txt
  43. tyrion@aws:~/src/bash$ time python sort1.py input.txt out.txt
  44.  
  45. real 0m0.031s
  46. user 0m0.020s
  47. sys 0m0.012s
Advertisement
Add Comment
Please, Sign In to add comment