Skip to content

Commit 05d7ec3

Browse files
authored
Add libsodium benchmark (#2025)
1 parent bab2402 commit 05d7ec3

9 files changed

Lines changed: 131 additions & 7 deletions

File tree

.github/workflows/compilation_on_android_ubuntu.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ jobs:
515515
git fetch https://github.com/WebAssembly/wasi-libc \
516516
8f5275796a82f8ecfd0833a4f3f444fa37ed4546
517517
git checkout FETCH_HEAD
518-
make \
518+
make -j \
519519
AR=/opt/wasi-sdk/bin/llvm-ar \
520520
NM=/opt/wasi-sdk/bin/llvm-nm \
521521
CC=/opt/wasi-sdk/bin/clang \

tests/benchmarks/coremark/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Please build iwasm and wamrc, refer to:
1010
- [Build iwasm on Linux](../../../doc/build_wamr.md#linux), or [Build iwasm on MacOS](../../../doc/build_wamr.md#macos)
11-
- [build wamrc AOT compiler](../../../README.md#build-wamrc-aot-compiler)
11+
- [Build wamrc AOT compiler](../../../README.md#build-wamrc-aot-compiler)
1212

1313
And install WASI SDK, please download the [wasi-sdk release](https://github.com/CraneStation/wasi-sdk/releases) and extract the archive to default path `/opt/wasi-sdk`.
1414

tests/benchmarks/coremark/build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ cd coremark
1313

1414
echo "Build coremark with gcc .."
1515
gcc -O3 -Iposix -I. -DFLAGS_STR=\""-O3 -DPERFORMANCE_RUN=1 -lrt"\" \
16-
-DITERATIONS=0 -DPERFORMANCE_RUN=1 \
16+
-DITERATIONS=400000 -DSEED_METHOD=SEED_VOLATILE -DPERFORMANCE_RUN=1 \
1717
core_list_join.c core_main.c core_matrix.c core_state.c \
1818
core_util.c posix/core_portme.c \
1919
-o ../coremark.exe -lrt
2020

2121
echo "Build coremark with wasi-sdk .."
2222
/opt/wasi-sdk/bin/clang -O3 -Iposix -I. -DFLAGS_STR=\""-O3 -DPERFORMANCE_RUN=1"\" \
2323
-Wl,--export=main \
24-
-DITERATIONS=0 -DPERFORMANCE_RUN=1 \
24+
-DITERATIONS=400000 -DSEED_METHOD=SEED_VOLATILE -DPERFORMANCE_RUN=1 \
2525
-Wl,--allow-undefined \
2626
core_list_join.c core_main.c core_matrix.c core_state.c \
2727
core_util.c posix/core_portme.c \

tests/benchmarks/jetstream/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Please build iwasm and wamrc, refer to:
1010
- [Build iwasm on Linux](../../../doc/build_wamr.md#linux), or [Build iwasm on MacOS](../../../doc/build_wamr.md#macos)
11-
- [build wamrc AOT compiler](../../../README.md#build-wamrc-aot-compiler)
11+
- [Build wamrc AOT compiler](../../../README.md#build-wamrc-aot-compiler)
1212

1313
And install emsdk, refer to [the guide](https://emscripten.org/docs/getting_started/downloads.html). Don't forget to activate
1414
emsdk and set up environment variables. For example, use instructions below to install it under /opt and activate it:
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Introduction
2+
3+
[libsodium](https://github.com/jedisct1/libsodium) is a new, easy-to-use software library for encryption, decryption, signatures, password hashing and more.
4+
5+
**Source**: https://github.com/jedisct1/libsodium
6+
7+
# Building
8+
9+
Please build iwasm and wamrc, refer to:
10+
- [Build iwasm on Linux](../../../doc/build_wamr.md#linux), or [Build iwasm on MacOS](../../../doc/build_wamr.md#macos)
11+
- [Build wamrc AOT compiler](../../../README.md#build-wamrc-aot-compiler)
12+
13+
And install [zig toolchain](https://ziglang.org/learn/getting-started), refer to [Install Zig from a Package Manager](https://github.com/ziglang/zig/wiki/Install-Zig-from-a-Package-Manager) for how to install it.
14+
15+
And then run `./build.sh` to build the source code, the libsodium source code will be cloned, and test benchmarks of native version, wasm files and AOT files will be generated under `libsodium/zig-out/bin`.
16+
17+
# Running
18+
19+
Run `./run_aot.sh` to test the benchmark, the native mode and iwasm aot mode will be tested respectively.
20+
21+
# Others
22+
23+
Refer to [Performance of WebAssembly runtimes in 2023](https://00f.net/2023/01/04/webassembly-benchmark-2023) for more about the performance comparison of wasm runtimes on running the libsodium benchmarks.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
# Copyright (C) 2019 Intel Corporation. All rights reserved.
4+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
6+
libsodium_CASES="aead_aes256gcm2 aead_aes256gcm aead_chacha20poly13052 aead_chacha20poly1305 \
7+
aead_xchacha20poly1305 auth2 auth3 auth5 auth6 auth7 auth box2 box7 box8 \
8+
box_easy2 box_easy box_seal box_seed box chacha20 codecs core1 core2 core3 \
9+
core4 core5 core6 core_ed25519 core_ristretto255 ed25519_convert generichash2 \
10+
generichash3 generichash hash3 hash kdf keygen kx metamorphic misuse \
11+
onetimeauth2 onetimeauth7 onetimeauth pwhash_argon2id pwhash_argon2i \
12+
pwhash_scrypt_ll pwhash_scrypt randombytes scalarmult2 scalarmult5 \
13+
scalarmult6 scalarmult7 scalarmult8 scalarmult_ed25519 scalarmult_ristretto255 \
14+
scalarmult secretbox2 secretbox7 secretbox8 secretbox_easy2 secretbox_easy \
15+
secretbox secretstream shorthash sign siphashx24 sodium_core sodium_utils2 \
16+
sodium_utils3 sodium_utils sodium_version stream2 stream3 stream4 stream verify1 \
17+
xchacha20"
18+
19+
readonly WAMRC_CMD=$PWD/../../../wamr-compiler/build/wamrc
20+
readonly OUT_DIR=$PWD/libsodium/zig-out/bin
21+
22+
if [ ! -d libsodium ]; then
23+
git clone -b stable https://github.com/jedisct1/libsodium.git
24+
fi
25+
26+
cd libsodium
27+
28+
echo "Build libsodium native"
29+
zig build -Drelease-fast -Denable_benchmarks=true
30+
31+
echo "Build libsodium wasm32-wasi"
32+
zig build -Drelease-fast -Denable_benchmarks=true -Dtarget=wasm32-wasi
33+
34+
for case in ${libsodium_CASES}
35+
do
36+
${WAMRC_CMD} -o ${OUT_DIR}/${case}.aot ${OUT_DIR}/${case}.wasm
37+
38+
if [ "$?" != 0 ]; then
39+
echo -e "Error while compiling ${case}.wasm to ${case}.aot"
40+
exit
41+
fi
42+
done
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/bash
2+
3+
# Copyright (C) 2019 Intel Corporation. All rights reserved.
4+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
6+
libsodium_CASES="aead_aes256gcm2 aead_aes256gcm aead_chacha20poly13052 aead_chacha20poly1305 \
7+
aead_xchacha20poly1305 auth2 auth3 auth5 auth6 auth7 auth box2 box7 box8 \
8+
box_easy2 box_easy box_seal box_seed box chacha20 codecs core1 core2 core3 \
9+
core4 core5 core6 core_ed25519 core_ristretto255 ed25519_convert generichash2 \
10+
generichash3 generichash hash3 hash kdf keygen kx metamorphic misuse \
11+
onetimeauth2 onetimeauth7 onetimeauth pwhash_argon2id pwhash_argon2i \
12+
pwhash_scrypt_ll pwhash_scrypt randombytes scalarmult2 scalarmult5 \
13+
scalarmult6 scalarmult7 scalarmult8 scalarmult_ed25519 scalarmult_ristretto255 \
14+
scalarmult secretbox2 secretbox7 secretbox8 secretbox_easy2 secretbox_easy \
15+
secretbox secretstream shorthash sign siphashx24 sodium_core sodium_utils2 \
16+
sodium_utils3 sodium_utils sodium_version stream2 stream3 stream4 stream verify1 \
17+
xchacha20"
18+
19+
readonly OUT_DIR=$PWD/libsodium/zig-out/bin
20+
readonly REPORT=$PWD/report.txt
21+
readonly IWASM_CMD=$PWD/../../../product-mini/platforms/linux/build/iwasm
22+
23+
BENCH_NAME_MAX_LEN=20
24+
25+
rm -f $REPORT
26+
touch $REPORT
27+
28+
function print_bench_name()
29+
{
30+
name=$1
31+
echo -en "$name" >> $REPORT
32+
name_len=${#name}
33+
if [ $name_len -lt $BENCH_NAME_MAX_LEN ]
34+
then
35+
spaces=$(( $BENCH_NAME_MAX_LEN - $name_len ))
36+
for i in $(eval echo "{1..$spaces}"); do echo -n " " >> $REPORT; done
37+
fi
38+
}
39+
40+
# run benchmarks
41+
cd $OUT_DIR
42+
43+
echo -en "\t\t\t\t\t\tnative\tiwasm-aot\n" >> $REPORT
44+
45+
for t in $libsodium_CASES
46+
do
47+
print_bench_name $t
48+
49+
echo "run $t with native..."
50+
echo -en "\t" >> $REPORT
51+
./${t} | awk -F '-' 'BEGIN{FIELDWIDTHS="10"}{ORS=""; print $1 / 1000000.0}' >> $REPORT
52+
53+
echo "run $t with iwasm aot..."
54+
echo -en "\t \t" >> $REPORT
55+
$IWASM_CMD ${t}.aot | awk -F '-' 'BEGIN{FIELDWIDTHS="10"}{ORS=""; print $1 / 1000000.0}' >> $REPORT
56+
57+
echo -en "\n" >> $REPORT
58+
done
59+

tests/benchmarks/polybench/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Please build iwasm and wamrc, refer to:
1010
- [Build iwasm on Linux](../../../doc/build_wamr.md#linux), or [Build iwasm on MacOS](../../../doc/build_wamr.md#macos)
11-
- [build wamrc AOT compiler](../../../README.md#build-wamrc-aot-compiler)
11+
- [Build wamrc AOT compiler](../../../README.md#build-wamrc-aot-compiler)
1212

1313
And install WASI SDK, please download the [wasi-sdk release](https://github.com/CraneStation/wasi-sdk/releases) and extract the archive to default path `/opt/wasi-sdk`.
1414

tests/benchmarks/sightglass/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Please build iwasm and wamrc, refer to:
1010
- [Build iwasm on Linux](../../../doc/build_wamr.md#linux), or [Build iwasm on MacOS](../../../doc/build_wamr.md#macos)
11-
- [build wamrc AOT compiler](../../../README.md#build-wamrc-aot-compiler)
11+
- [Build wamrc AOT compiler](../../../README.md#build-wamrc-aot-compiler)
1212

1313
And install WASI SDK, please download the [wasi-sdk release](https://github.com/CraneStation/wasi-sdk/releases) and extract the archive to default path `/opt/wasi-sdk`.
1414

0 commit comments

Comments
 (0)