1. aobench各算法性能验证
4 核Intel i7-7700 CPU@ 3.60GHz, ispc_tasks性能比tiled_par性能更优。
# export FEATURES=ispc
# ./benchmark.sh
+ export WIDTH=800
+ WIDTH=800
+ export HEIGHT=600
+ HEIGHT=600
+ [[ '' != 1 ]]
+ hash hyperfine
+ ALGS=("scalar" "scalar_par" "vector" "vector_par" "tiled" "tiled_par")
+ echo ispc
+ grep -q ispc
+ hash ispc
+ ALGS+=("ispc" "ispc_tasks")
+ echo 'Benchmark 256-bit wide vectors'
Benchmark 256-bit wide vectors
+ RUSTFLAGS='-C target-cpu=native '
+ cargo build --release --no-default-features --features=ispc,256bit
Finished release [optimized] target(s) in 0.09s
+ [[ '' == \1 ]]
+ [[ '' == \1 ]]
+ for alg in '"${ALGS[@]}"'
+ hyperfine '../target/release/aobench 800 600 --algo scalar'
Benchmark #1: ../target/release/aobench 800 600 --algo scalar
Time (mean ± σ): 3.591 s ± 0.096 s [User: 3.442 s, System: 0.042 s]
Range (min … max): 3.463 s … 3.702 s 10 runs
+ for alg in '"${ALGS[@]}"'
+ hyperfine '../target/release/aobench 800 600 --algo scalar_par'
Benchmark #1: ../target/release/aobench 800 600 --algo scalar_par
Time (mean ± σ): 1.052 s ± 0.042 s [User: 3.112 s, System: 0.281 s]
Range (min … max): 1.010 s … 1.149 s 10 runs
+ for alg in '"${ALGS[@]}"'
+ hyperfine '../target/release/aobench 800 600 --algo vector'
Benchmark #1: ../target/release/aobench 800 600 --algo vector
Time (mean ± σ): 1.544 s ± 0.048 s [User: 1.482 s, System: 0.016 s]
Range (min … max): 1.497 s … 1.630 s 10 runs
+ for alg in '"${ALGS[@]}"'
+ hyperfine '../target/release/aobench 800 600 --algo vector_par'
Benchmark #1: ../target/release/aobench 800 600 --algo vector_par
Time (mean ± σ): 511.1 ms ± 43.5 ms [User: 1.368 s, System: 0.219 s]
Range (min … max): 471.1 ms … 603.7 ms 10 runs
Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet PC without any interferences from other programs. It might help to use the'--warmup' or '--prepare' options.
+ for alg in '"${ALGS[@]}"'
+ hyperfine '../target/release/aobench 800 600 --algo tiled'
Benchmark #1: ../target/release/aobench 800 600 --algo tiled
Time (mean ± σ): 1.665 s ± 0.120 s [User: 1.605 s, System: 0.028 s]
Range (min … max): 1.540 s … 1.970 s 10 runs
Warning: The first benchmarking run for this command was significantly slower than the rest (1.970 s). This could be caused by (filesystem) caches that were not filled until after the first run. You should consider using the '--warmup' option to fill those caches before the actual benchmark. Alternatively, use the '--prepare' option to clear the caches before each timing run.
+ for alg in '"${ALGS[@]}"'
+ hyperfine '../target/release/aobench 800 600 --algo tiled_par'
Benchmark #1: ../target/release/aobench 800 600 --algo tiled_par
Time (mean ± σ): 568.6 ms ± 38.6 ms [User: 1.486 s, System: 0.222 s]
Range (min … max): 519.4 ms … 654.5 ms 10 runs
+ for alg in '"${ALGS[@]}"'
+ hyperfine '../target/release/aobench 800 600 --algo ispc'
Benchmark #1: ../target/release/aobench 800 600 --algo ispc
Time (mean ± σ): 794.9 ms ± 46.3 ms [User: 729.2 ms, System: 21.3 ms]
Range (min … max): 723.2 ms … 844.7 ms 10 runs
+ for alg in '"${ALGS[@]}"'
+ hyperfine '../target/release/aobench 800 600 --algo ispc_tasks'
Benchmark #1: ../target/release/aobench 800 600 --algo ispc_tasks
Time (mean ± σ): 369.3 ms ± 25.5 ms [User: 775.5 ms, System: 224.7 ms]
Range (min … max): 338.8 ms … 413.0 ms 10 runs
+ echo 'Benchmark 128-bit wide vectors'
Benchmark 128-bit wide vectors
+ RUSTFLAGS='-C target-cpu=native '
+ cargo build --release --no-default-features --features=ispc
Finished release [optimized] target(s) in 0.10s
+ for alg in '"${ALGS[@]}"'
+ hyperfine '../target/release/aobench 800 600 --algo scalar'
Benchmark #1: ../target/release/aobench 800 600 --algo scalar
Time (mean ± σ): 4.056 s ± 0.163 s [User: 3.898 s, System: 0.047 s]
Range (min … max): 3.811 s … 4.264 s 10 runs
+ for alg in '"${ALGS[@]}"'
+ hyperfine '../target/release/aobench 800 600 --algo scalar_par'
Benchmark #1: ../target/release/aobench 800 600 --algo scalar_par
Time (mean ± σ): 1.409 s ± 0.072 s [User: 3.736 s, System: 0.454 s]
Range (min … max): 1.263 s … 1.506 s 10 runs
+ for alg in '"${ALGS[@]}"'
+ hyperfine '../target/release/aobench 800 600 --algo vector'
Benchmark #1: ../target/release/aobench 800 600 --algo vector
Time (mean ± σ): 1.980 s ± 0.154 s [User: 1.935 s, System: 0.018 s]
Range (min … max): 1.816 s … 2.250 s 10 runs
+ for alg in '"${ALGS[@]}"'
+ hyperfine '../target/release/aobench 800 600 --algo vector_par'
Benchmark #1: ../target/release/aobench 800 600 --algo vector_par
Time (mean ± σ): 665.0 ms ± 66.5 ms [User: 1.735 s, System: 0.254 s]
Range (min … max): 597.1 ms … 767.1 ms 10 runs
+ for alg in '"${ALGS[@]}"'
+ hyperfine '../target/release/aobench 800 600 --algo tiled'
Benchmark #1: ../target/release/aobench 800 600 --algo tiled
Time (mean ± σ): 1.802 s ± 0.050 s [User: 1.707 s, System: 0.031 s]
Range (min … max): 1.724 s … 1.872 s 10 runs
+ for alg in '"${ALGS[@]}"'
+ hyperfine '../target/release/aobench 800 600 --algo tiled_par'
Benchmark #1: ../target/release/aobench 800 600 --algo tiled_par
Time (mean ± σ): 592.8 ms ± 38.1 ms [User: 1.635 s, System: 0.206 s]
Range (min … max): 553.6 ms … 643.2 ms 10 runs
+ for alg in '"${ALGS[@]}"'
+ hyperfine '../target/release/aobench 800 600 --algo ispc'
Benchmark #1: ../target/release/aobench 800 600 --algo ispc
Time (mean ± σ): 728.3 ms ± 23.4 ms [User: 670.4 ms, System: 21.7 ms]
Range (min … max): 701.5 ms … 774.4 ms 10 runs
+ for alg in '"${ALGS[@]}"'
+ hyperfine '../target/release/aobench 800 600 --algo ispc_tasks'
Benchmark #1: ../target/release/aobench 800 600 --algo ispc_tasks
Time (mean ± σ): 290.9 ms ± 13.5 ms [User: 646.4 ms, System: 155.7 ms]
Range (min … max): 263.2 ms … 312.9 ms 10 runs
如遇到提示找不到libclang.so或者stdtool.h等bug,做如下操作可解决:
apt-get install libclang-dev
apt-get update
apt-get install clang
ispc的安装直接从github下载相应的安装包,解压出来,ln -s ispc-v1.12.0-linux/bin/ispc /usr/bin/
即可。
参考资料:
[1] https://github.com/rust-lang-nursery/packed_simd/tree/master/examples/aobench