sistema_progs

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

array-access.sh (3046B)


      1 #!/usr/bin/env bash
      2 
      3 if [[ ! ${BLE_VERSION-} ]]; then
      4   source ../../src/benchmark.sh
      5 fi
      6 
      7 function measure-array.1 {
      8   local N=$1
      9   eval "local -a a=({1..$N})"
     10   ble-measure "$2"
     11 }
     12 function measure-array {
     13   measure-array.1 10     "$1 10    "
     14   measure-array.1 100    "$1 100   "
     15   measure-array.1 1000   "$1 1000  "
     16   measure-array.1 10000  "$1 10000 "
     17   measure-array.1 100000 "$1 100000"
     18 }
     19 function sum-forward  { local s=0; for ((i=0;i<N;i++)); do ((s+=a[i])); done       ; }
     20 function sum-backward { local s=0; for ((i=N;--i>=0;)); do ((s+=a[i])); done       ; }
     21 function sum-random   { local s=0; for ((i=0;i<N;i++)); do ((s+=a[RANDOM%N])); done; }
     22 
     23 measure-array sum-forward 
     24 measure-array sum-backward
     25 measure-array sum-random  
     26 
     27 # bash-dev
     28 #      38.371 usec/eval: sum-forward 10     (x5000)
     29 #     311.913 usec/eval: sum-forward 100    (x500)
     30 #    3046.322 usec/eval: sum-forward 1000   (x50)
     31 #   30699.500 usec/eval: sum-forward 10000  (x5)
     32 #  309013.300 usec/eval: sum-forward 100000 (x1)
     33 #      33.804 usec/eval: sum-backward 10     (x5000)
     34 #     269.811 usec/eval: sum-backward 100    (x500)
     35 #    2645.302 usec/eval: sum-backward 1000   (x50)
     36 #   26564.500 usec/eval: sum-backward 10000  (x5)
     37 #  266084.300 usec/eval: sum-backward 100000 (x1)
     38 #      45.826 usec/eval: sum-random 10     (x5000)
     39 #     399.209 usec/eval: sum-random 100    (x500)
     40 #    4580.182 usec/eval: sum-random 1000   (x50)
     41 #  135904.300 usec/eval: sum-random 10000  (x1)
     42 # 3693072.300 usec/eval: sum-random 100000 (x1)
     43 
     44 # bash-5.0
     45 #      38.723 usec/eval: sum-forward 10     (x5000)
     46 #     322.861 usec/eval: sum-forward 100    (x500)
     47 #    3188.720 usec/eval: sum-forward 1000   (x50)
     48 #   31446.200 usec/eval: sum-forward 10000  (x5)
     49 #  317422.600 usec/eval: sum-forward 100000 (x1)
     50 #      34.875 usec/eval: sum-backward 10     (x5000)
     51 #     286.639 usec/eval: sum-backward 100    (x500)
     52 #    2826.220 usec/eval: sum-backward 1000   (x50)
     53 #   27921.600 usec/eval: sum-backward 10000  (x5)
     54 #  283819.600 usec/eval: sum-backward 100000 (x1)
     55 #      46.838 usec/eval: sum-random 10     (x2000)
     56 #     414.663 usec/eval: sum-random 100    (x500)
     57 #    5517.050 usec/eval: sum-random 1000   (x20)
     58 #  123421.600 usec/eval: sum-random 10000  (x1)
     59 # 4942400.600 usec/eval: sum-random 100000 (x1)
     60 
     61 # bash-4.4
     62 #       41.660 usec/eval: sum-forward 10     (x5000)
     63 #      354.000 usec/eval: sum-forward 100    (x500)
     64 #     3416.000 usec/eval: sum-forward 1000   (x50)
     65 #    34200.000 usec/eval: sum-forward 10000  (x5)
     66 #   347000.000 usec/eval: sum-forward 100000 (x1)
     67 #       37.060 usec/eval: sum-backward 10     (x5000)
     68 #      316.000 usec/eval: sum-backward 100    (x500)
     69 #     5095.000 usec/eval: sum-backward 1000   (x20)
     70 #   242000.000 usec/eval: sum-backward 10000  (x1)
     71 # 19999000.000 usec/eval: sum-backward 100000 (x1)
     72 #       51.050 usec/eval: sum-random 10     (x2000)
     73 #      454.000 usec/eval: sum-random 100    (x500)
     74 #     5895.000 usec/eval: sum-random 1000   (x20)
     75 #   172000.000 usec/eval: sum-random 10000  (x1)
     76 #  4577000.000 usec/eval: sum-random 100000 (x1)