0. Contents
1.Concept
2.Test Script
3.Run Test
4.Summary
Script1
#! /usr/bin/env bash
seq 1 100 > test.txt
test1(){
for (( i=1; i <= 100; i++ )) ; do
a=$( head -n "$i" test.txt | tail -n 1 )
done
}
test2(){
for (( i=1; i <= 100; i++ )) ; do
a=$( sed -n "$i p" test.txt )
done
}
test3(){
for (( i=1; i <= 100; i++ )) ; do
a=$( head -n 1 test.txt )
done
}
time test1
time test2
time test3
exit
|
Script2
#! /usr/bin/env bash
seq 1 100 > test.txt
a=$( head -n 12 test.txt | tail -n 5 )
b=$( sed -n '8,12 p' test.txt )
c=$( head -n 102 test.txt | tail -n 5 )
d=$( sed -n '98,102 p' test.txt )
echo -e "a\n$a\n"
echo -e "b\n$b\n"
echo -e "c\n$c\n"
echo -e "d\n$d\n"
exit
|
Script1
test1: head -n "$i" test.txt | tail -n 1
real 0m2.499s
user 0m1.840s
sys 0m0.620s
test2: sed -n "$i p" test.txt
real 0m0.312s
user 0m0.140s
sys 0m0.170s
test3: head -n 1 test.txt
real 0m1.209s
user 0m0.920s
sys 0m0.280s
|
Script2
a
8
9
10
11
12
b
8
9
10
11
12
c
96
97
98
99
100
d
98
99
100
|