0. Contents
1.Concept
2.Test Script
3.Run Test
4.Summary
Script1
#! /usr/bin/env bash
declare -i a=0 b=10000
test1(){
local a="$a" b="$b"
while [ $a -lt $b ] ; do
(( a++ ))
done
}
test2(){
local a="$a" b="$b"
while (( a < b )) ; do
(( a++ ))
done
}
time test1
time test2
exit
|
Script2
#! /usr/bin/env bash
function test(){
[ "$1" -gt 0 ] && echo 'test1 OK'
[ "$1" = 1 ] && echo 'test2 OK'
(( "$1" > 0 )) && echo 'test3 OK'
(( "$1" == 1 )) && echo 'test4 OK'
}
test 1
test 2
test '2-1'
exit
|
Script1
test1
real 0m0.766s
user 0m0.750s
sys 0m0.010s
test2
real 0m0.497s
user 0m0.490s
sys 0m0.000s
|
Script2
"1" の場合
test1 OK
test2 OK
test3 OK
test4 OK
"2" の場合
test1 OK
test3 OK
"2-1" の場合
[: 2-1: integer expression expected
test3 OK
test4 OK
|