Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- NOTES:
- The INPUT and OUTPUT values are in characters. The objective here is to, as
- quickly as possible, trim a string to be no more N characters long. Here we pit
- two competing approaches against each other, both using sh(1). One approach
- uses a fork to awk(1) to trim the string to length. The competing approach
- doesn't use any forks, but instead a novel algorithm based on sh(1) built-ins.
- The awk(1) used is BSD's one-true-awk and the sh(1) used is FreeBSD's /bin/sh.
- All the awk(1) is doing is basically a substr() of the input (multine allowed).
- The competing sh(1)-only approach designed to defeat a fork to awk(1) uses a
- dual-approach of calculating least-work to get to the answer and choosing the
- best approach for each round (as multiple rounds are required to achieve the
- desired result) based on built-in capabilities of FreeBSD's sh(1).
- Let the battle begin:
- LOOP-RUNS INPUT OUTPUT AWK-TIME SH-TIME WINNER
- 1 10 6 0.017s 0.012s SH
- 10 10 6 0.055s 0.014s SH
- 100 10 6 0.436s 0.030s SH
- 1000 10 6 4.518s 0.187s SH
- 10000 10 6 45.299s 1.829s SH
- 1 1035 6 0.022s 0.020s SH
- 10 1035 6 0.061s 0.021s SH
- 100 1035 6 0.462s 0.041s SH
- 1000 1035 6 4.518s 0.233s SH
- 10000 1035 6 50.581s 2.129s SH
- 1 10251 6 0.024s 0.020s SH
- 10 10251 6 0.072s 0.027s SH
- 100 10251 6 0.509s 0.085s SH
- 1000 10251 6 4.902s 0.744s SH
- 10000 10251 6 50.073s 7.461s SH
- 1 10 4 0.016s 0.012s SH
- 10 10 4 0.056s 0.014s SH
- 100 10 4 0.469s 0.028s SH
- 1000 10 4 4.722s 0.168s SH
- 10000 10 4 49.260s 1.588s SH
- 1 1035 1029 0.023s 0.020s SH
- 10 1035 1029 0.065s 0.022s SH
- 100 1035 1029 0.490s 0.038s SH
- 1000 1035 1029 5.002s 0.223s SH
- 10000 1035 1029 51.070s 1.954s SH
- 1 10251 10245 0.025s 0.021s SH
- 10 10251 10245 0.069s 0.025s SH
- 100 10251 10245 0.511s 0.082s SH
- 1000 10251 10245 5.382s 0.583s SH
- 10000 10251 10245 56.065s 5.817s SH
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement