Advertisement
devinteske

sh(1) based snprintf-approach battle

Jan 24th, 2016
521
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. NOTES:
  2. The INPUT and OUTPUT values are in characters. The objective here is to, as
  3. quickly as possible, trim a string to be no more N characters long. Here we pit
  4. two competing approaches against each other, both using sh(1). One approach
  5. uses a fork to awk(1) to trim the string to length. The competing approach
  6. doesn't use any forks, but instead a novel algorithm based on sh(1) built-ins.
  7.  
  8. The awk(1) used is BSD's one-true-awk and the sh(1) used is FreeBSD's /bin/sh.
  9. All the awk(1) is doing is basically a substr() of the input (multine allowed).
  10. The competing sh(1)-only approach designed to defeat a fork to awk(1) uses a
  11. dual-approach of calculating least-work to get to the answer and choosing the
  12. best approach for each round (as multiple rounds are required to achieve the
  13. desired result) based on built-in capabilities of FreeBSD's sh(1).
  14.  
  15. Let the battle begin:
  16.  
  17. LOOP-RUNS INPUT OUTPUT AWK-TIME SH-TIME WINNER
  18. 1 10 6 0.017s 0.012s SH
  19. 10 10 6 0.055s 0.014s SH
  20. 100 10 6 0.436s 0.030s SH
  21. 1000 10 6 4.518s 0.187s SH
  22. 10000 10 6 45.299s 1.829s SH
  23. 1 1035 6 0.022s 0.020s SH
  24. 10 1035 6 0.061s 0.021s SH
  25. 100 1035 6 0.462s 0.041s SH
  26. 1000 1035 6 4.518s 0.233s SH
  27. 10000 1035 6 50.581s 2.129s SH
  28. 1 10251 6 0.024s 0.020s SH
  29. 10 10251 6 0.072s 0.027s SH
  30. 100 10251 6 0.509s 0.085s SH
  31. 1000 10251 6 4.902s 0.744s SH
  32. 10000 10251 6 50.073s 7.461s SH
  33. 1 10 4 0.016s 0.012s SH
  34. 10 10 4 0.056s 0.014s SH
  35. 100 10 4 0.469s 0.028s SH
  36. 1000 10 4 4.722s 0.168s SH
  37. 10000 10 4 49.260s 1.588s SH
  38. 1 1035 1029 0.023s 0.020s SH
  39. 10 1035 1029 0.065s 0.022s SH
  40. 100 1035 1029 0.490s 0.038s SH
  41. 1000 1035 1029 5.002s 0.223s SH
  42. 10000 1035 1029 51.070s 1.954s SH
  43. 1 10251 10245 0.025s 0.021s SH
  44. 10 10251 10245 0.069s 0.025s SH
  45. 100 10251 10245 0.511s 0.082s SH
  46. 1000 10251 10245 5.382s 0.583s SH
  47. 10000 10251 10245 56.065s 5.817s SH
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement