sistema_progs

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

D1302.benchmark-c2s-cached.sh (6223B)


      1 #!/bin/bash
      2 
      3 source src/benchmark.sh
      4 
      5 ble/util/c2s.0() { :; }
      6 
      7 table1=$' \x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F'
      8 table1=$table1$'\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F'
      9 table1=$table1$'\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F'
     10 table1=$table1$'\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F'
     11 table1=$table1$'\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F'
     12 table1=$table1$'\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x5B\x5C\x5D\x5E\x5F'
     13 table1=$table1$'\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F'
     14 table1=$table1$'\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7A\x7B\x7C\x7D\x7E\x7F'
     15 ble/util/c2s.1() {
     16   if ((c<0x80)); then
     17     ret=${table1:c:1}
     18   else
     19     ret=something
     20   fi
     21 }
     22 
     23 for i in {0..127}; do
     24   table2[i]=${table1:i:1}
     25 done
     26 ble/util/c2s.2() {
     27   ret=${table2[c]}
     28   if [[ ! $ret ]]; then
     29     ret=something
     30   fi
     31 }
     32 
     33 #------------------------------------------------------------------------------
     34 
     35 set +f
     36 input=($(od -vAn -tx1 /dev/urandom | head -200 | od -vAn -td1))
     37 function tester.loop {
     38   local ret
     39   for c; do
     40     "$c2s" "$c"
     41   done
     42 }
     43 function tester {
     44   local c2s=$1
     45   tester.loop "${input[@]}"
     46 }
     47 
     48 # ble-measure 'tester ble/util/c2s.0'
     49 # ble-measure 'tester ble/util/c2s.1'
     50 # ble-measure 'tester ble/util/c2s.2'
     51 
     52 # bash-5.0
     53 # 68272.500 usec/eval: tester ble/util/c2s.1 (x2)
     54 # 87022.500 usec/eval: tester ble/util/c2s.2 (x2)
     55 
     56 # bash-4.2
     57 # 12300000.000 usec/eval: tester ble/util/c2s.1 (x1)
     58 # 12323000.000 usec/eval: tester ble/util/c2s.2 (x1)
     59 
     60 # bash-4.0
     61 # 12262000.000 usec/eval: tester ble/util/c2s.1 (x1)
     62 # 12323000.000 usec/eval: tester ble/util/c2s.2 (x1)
     63 
     64 #------------------------------------------------------------------------------
     65 # どうも遅いのは c2s を辞書から引く操作ではなくて、大量の引数を抱えた
     66 # 関数から子関数を呼び出す時の動作の様である。
     67 # 次に引数を小分けにして呼び出す事を考えてみる。
     68 # 結果を見ると Bash-5.0 ではまとめて呼び出す方が速いが、
     69 # Bash-4.4 以下では分割した方が速い。
     70 # 色々計測しても一定しないが大体 150-170 辺りが最小になるだろうか。
     71 
     72 function tester.2/loop1 {
     73   local N=$# i
     74   for ((i=0;i+B<N;i+=B)); do
     75     tester.loop "${@:i+1:B}"
     76   done
     77   ((i<N)) && tester.loop "${@:i+1:N-i}"
     78 }
     79 function tester.2 {
     80   local c2s=$1 B=${2:-100}
     81   tester.2/loop1 "${input[@]}"
     82 }
     83 # ble-measure 'tester.2 ble/util/c2s.0 5'
     84 # ble-measure 'tester.2 ble/util/c2s.0 10'
     85 # ble-measure 'tester.2 ble/util/c2s.0 20'
     86 # ble-measure 'tester.2 ble/util/c2s.0 50'
     87 # ble-measure 'tester.2 ble/util/c2s.0 100'
     88 # ble-measure 'tester.2 ble/util/c2s.0 200'
     89 # ble-measure 'tester.2 ble/util/c2s.0 500'
     90 # ble-measure 'tester.2 ble/util/c2s.0 1000'
     91 # ble-measure 'tester.2 ble/util/c2s.0 2000'
     92 # ble-measure 'tester.2 ble/util/c2s.0 5000'
     93 # ble-measure 'tester.2 ble/util/c2s.0 10000'
     94 
     95 # bash-4.0
     96 # 21591000.000 usec/eval: tester.2 ble/util/c2s.0 2 (x1)
     97 #  8790000.000 usec/eval: tester.2 ble/util/c2s.0 5 (x1)
     98 #  4481000.000 usec/eval: tester.2 ble/util/c2s.0 10 (x1)
     99 #  2276000.000 usec/eval: tester.2 ble/util/c2s.0 20 (x1)
    100 #   982000.000 usec/eval: tester.2 ble/util/c2s.0 50 (x1)
    101 #   603000.000 usec/eval: tester.2 ble/util/c2s.0 100 (x1)
    102 #   513000.000 usec/eval: tester.2 ble/util/c2s.0 200 (x1)
    103 #   747000.000 usec/eval: tester.2 ble/util/c2s.0 500 (x1)
    104 #  1297000.000 usec/eval: tester.2 ble/util/c2s.0 1000 (x1)
    105 #  2491000.000 usec/eval: tester.2 ble/util/c2s.0 2000 (x1)
    106 #  6045000.000 usec/eval: tester.2 ble/util/c2s.0 5000 (x1)
    107 # 12179000.000 usec/eval: tester.2 ble/util/c2s.0 10000 (x1)
    108 
    109 # bash-5.0
    110 # 4975379.200 usec/eval: tester.2 ble/util/c2s.0 5 (x1)
    111 # 2594160.200 usec/eval: tester.2 ble/util/c2s.0 10 (x1)
    112 # 1371359.200 usec/eval: tester.2 ble/util/c2s.0 20 (x1)
    113 #  591166.200 usec/eval: tester.2 ble/util/c2s.0 50 (x1)
    114 #  333587.200 usec/eval: tester.2 ble/util/c2s.0 100 (x1)
    115 #  199348.200 usec/eval: tester.2 ble/util/c2s.0 200 (x1)
    116 #  122687.200 usec/eval: tester.2 ble/util/c2s.0 500 (x1)
    117 #   95477.700 usec/eval: tester.2 ble/util/c2s.0 1000 (x2)
    118 #   82203.200 usec/eval: tester.2 ble/util/c2s.0 2000 (x2)
    119 #   72446.200 usec/eval: tester.2 ble/util/c2s.0 5000 (x2)
    120 #   68311.200 usec/eval: tester.2 ble/util/c2s.0 10000 (x2)
    121 
    122 # bash-4.4
    123 #  8066000.000 usec/eval: tester.2 ble/util/c2s.0 5 (x1)
    124 #  4074000.000 usec/eval: tester.2 ble/util/c2s.0 10 (x1)
    125 #  2070000.000 usec/eval: tester.2 ble/util/c2s.0 20 (x1)
    126 #   904000.000 usec/eval: tester.2 ble/util/c2s.0 50 (x1)
    127 #   528000.000 usec/eval: tester.2 ble/util/c2s.0 100 (x1)
    128 #   438000.000 usec/eval: tester.2 ble/util/c2s.0 200 (x1)
    129 #   705000.000 usec/eval: tester.2 ble/util/c2s.0 500 (x1)
    130 #  1290000.000 usec/eval: tester.2 ble/util/c2s.0 1000 (x1)
    131 #  2541000.000 usec/eval: tester.2 ble/util/c2s.0 2000 (x1)
    132 #  6197000.000 usec/eval: tester.2 ble/util/c2s.0 5000 (x1)
    133 # 12171000.000 usec/eval: tester.2 ble/util/c2s.0 10000 (x1)
    134 #   428000.000 usec/eval: tester.2 ble/util/c2s.0 150 (x1)
    135 #   435000.000 usec/eval: tester.2 ble/util/c2s.0 200 (x1)
    136 #   463000.000 usec/eval: tester.2 ble/util/c2s.0 250 (x1)
    137 #   494000.000 usec/eval: tester.2 ble/util/c2s.0 300 (x1)
    138 #   544000.000 usec/eval: tester.2 ble/util/c2s.0 350 (x1)
    139 #   586000.000 usec/eval: tester.2 ble/util/c2s.0 400 (x1)
    140 
    141 # 改めて計測する→対して違いは見られない
    142 # ble-measure 'tester.2 ble/util/c2s.0 160'
    143 # ble-measure 'tester.2 ble/util/c2s.1 160'
    144 # ble-measure 'tester.2 ble/util/c2s.2 160'
    145 
    146 #------------------------------------------------------------------------------
    147 # 実際に buff に値を格納して確かめてみる事にする
    148 # 然し、それでも大した計算時間の違いはない。
    149 
    150 function tester.3/loop2 {
    151   local ret
    152   for c; do
    153     "$c2s" "$c"
    154     buff[b++]=$ret
    155   done
    156 }
    157 function tester.3/loop1 {
    158   local N=$# i b=0
    159   local -a buff=()
    160   for ((i=0;i+B<N;i+=B)); do
    161     tester.3/loop2 "${@:i+1:B}"
    162   done
    163   ((i<N)) && tester.3/loop2 "${@:i+1:N-i}"
    164 }
    165 function tester.3 {
    166   local c2s=$1 B=${2:-160}
    167   tester.3/loop1 "${input[@]}"
    168 }
    169 
    170 # ble-measure 'tester.3 ble/util/c2s.0'
    171 # ble-measure 'tester.3 ble/util/c2s.1'
    172 # ble-measure 'tester.3 ble/util/c2s.2'