sistema_progs

Programas para customizar o meu entorno de traballo nos meus equipos persoais
Log | Files | Refs

201903-string-build.sh (1191B)


      1 #!/usr/bin/env bash
      2 
      3 if [[ ! ${BLE_VERSION-} ]]; then
      4   source ../../src/benchmark.sh
      5 fi
      6 
      7 #------------------------------------------------------------------------------
      8 
      9 function concat.str {
     10   local a out=
     11   for a in {1..1000}; do
     12     out=$out$a
     13   done
     14   ret=$out
     15 }
     16 function concat.ret {
     17   local a; ret=
     18   for a in {1..1000}; do
     19     ret=$ret$a
     20   done
     21 }
     22 function concat.arr {
     23   local a arr i=0; arr=()
     24   for a in {1..1000}; do
     25     arr[i++]=$a
     26   done
     27   ret="${arr[*]}"
     28 }
     29 
     30 function measure {
     31   local ret=
     32   ble-measure concat.str
     33   ble-measure concat.ret
     34   ble-measure concat.arr
     35 }
     36 measure
     37 
     38 #------------------------------------------------------------------------------
     39 
     40 function concatB.str {
     41   local a out= arr2; arr2=()
     42   for a in {1..1000}; do
     43     arr2[i%10]=$a
     44     out=$out$a
     45   done
     46   ret=$out
     47 }
     48 function concatB.ret {
     49   local a arr2; ret= arr2=()
     50   for a in {1..1000}; do
     51     arr2[i%10]=$a
     52     ret=$ret$a
     53   done
     54 }
     55 function concatB.arr {
     56   local a arr i=0 arr2; arr=() arr2=()
     57   for a in {1..1000}; do
     58     arr2[i%10]=$a
     59     arr[i++]=$a
     60   done
     61   ret="${arr[*]}"
     62 }
     63 
     64 function measureB {
     65   local ret=
     66   ble-measure concatB.str
     67   ble-measure concatB.ret
     68   ble-measure concatB.arr
     69 }
     70 measureB