Skip to content

Instantly share code, notes, and snippets.

@handymenny
Last active October 13, 2021 17:05
Show Gist options
  • Save handymenny/d28766a45de48d6962a9 to your computer and use it in GitHub Desktop.
Save handymenny/d28766a45de48d6962a9 to your computer and use it in GitHub Desktop.
zram benchmark
~ # /tmp/zramtest3.sh test6 /tmp/ffmpeg-1\:2.6.1-1-x86_64.pkg.tar
zram test6 Sat Apr 4 09:50:06 GMT 2015
comp_algorithm [lzo] lz4 snappy
real 0m 0.20s 0.20s 0.24s avg: 0.214s
real 0m 1.45s 1.42s 1.42s avg: 1.430s
compr_data_size 30504972 30504968 30504947 30504962
comp_algorithm lzo [lz4] snappy
real 0m 0.21s 0.21s 0.23s avg: 0.217s
real 0m 1.36s 1.36s 1.33s avg: 1.350s
compr_data_size 31234729 31234719 31234736 31234728
comp_algorithm lzo lz4 [snappy]
real 0m 0.22s 0.21s 0.21s avg: 0.214s
real 0m 1.56s 1.59s 1.56s avg: 1.570s
compr_data_size 30931116 30931087 30931076 30931093
Summary
Total average time
lzo: 1.644s
lz4: 1.567s
snappy: 1.784s
Average compr_data_size
lzo: 30504962
lz4: 31234728
snappy: 30931093
Gain
time= 4.7 % (lz4 vs lzo)
compression= 2.3% (lzo vs lz4)
######################----------------------TEST 1----------------------######################
~ # ./tmp/zramtest3.sh test1 /tmp/ffmpeg-1:2.6.1-1-x86_64.pkg.tar.xz 2
comp_algorithm [lzo] lz4 snappy
max_comp_streams 1
real 3.88s 3.92s 3.96s 3.91s 3.92s avg: 3.918s
user 2.62s 2.66s 2.70s 2.63s 2.72s
sys 1.24s 1.21s 1.13s 1.23s 1.18s
orig_data_size 23568384
compr_data_size 15235967 15235963 15235955 15235959 15235979 avg: 15235965
mem_used_total 16076800
max_comp_streams 2
real 3.92s 3.96s 3.94s 3.96s 3.92s avg: 3.940s
user 2.78s 2.63s 2.81s 2.68s 2.68s
sys 1.12s 1.31s 1.11s 1.24s 1.20s
orig_data_size 23568384
compr_data_size 15235975 15235967 15235965 15235968 15235954 avg: 15235966
mem_used_total 16080896
comp_algorithm lzo [lz4] snappy
max_comp_streams 1
real 3.88s 3.90s 3.90s 3.98s 3.95s avg: 3.922s
user 2.68s 2.67s 2.66s 2.76s 2.74s
sys 1.16s 1.21s 1.21s 1.20s 1.17s
orig_data_size 23568384
compr_data_size 15604605 15604624 15604604 15604600 15604612 avg: 15604609
mem_used_total 16433152
max_comp_streams 2
real 3.93s 3.90s 3.93s 3.90s 3.95s avg: 3.922s
user 2.63s 2.62s 2.68s 2.72s 2.93s
sys 1.27s 1.24s 1.23s 1.14s 1.29s
orig_data_size 23568384
compr_data_size 15604595 15604620 15604625 15604598 15604597 avg: 15604607
mem_used_total 16433152
comp_algorithm lzo lz4 [snappy]
max_comp_streams 1
real 3.95s 3.91s 3.97s 4.15s 3.95s avg: 3.986s
user 2.65s 2.78s 2.74s 2.69s 2.68s
sys 1.28s 1.09s 1.20s 1.21s 1.24s
orig_data_size 23568384
compr_data_size 15463010 15463013 15463025 15463011 15463019 avg: 15463016
mem_used_total 16162816
max_comp_streams 2
real 3.93s 3.97s 3.92s 3.90s 3.97s avg: 3.938s
user 2.76s 2.69s 2.67s 2.67s 2.73s
sys 1.13s 1.16s 1.22s 1.21s 1.20s
orig_data_size 23568384
compr_data_size 15463038 15463004 15463012 15463032 15463027 avg: 15463023
mem_used_total 16162816
######################----------------------TEST 2----------------------######################
~ # ./tmp/zramtest3.sh test2 /tmp/ffmpeg-1:2.6.1-1-x86_64.pkg.tar
comp_algorithm [lzo] lz4 snappy
max_comp_streams 1
real 0.32s 0.27s 0.32s 0.27s 0.31s avg: 0.298s
user 0.01s 0s 0.01s 0.02s 0.01s
sys 0.30s 0.26s 0.30s 0.25s 0.29s
orig_data_size 23568384
compr_data_size 15235914 15235895 15235903 15235921 15235922 avg: 15235911
mem_used_total 16076800
comp_algorithm lzo [lz4] snappy
max_comp_streams 1
real 0.29s 0.27s 0.31s 0.33s 0.34s avg: 0.308s
user 0.00s 0s 0.03s 0.00s 0.03s
sys 0.28s 0.27s 0.28s 0.32s 0.30s
orig_data_size 23568384
compr_data_size 15604514 15604560 15604541 15604513 15604512 avg: 15604528
mem_used_total 16449536
######################----------------------TEST 3----------------------######################
~ # ./tmp/zramtest3.sh test3 /system/app/LatinIME/LatinIME.apk
comp_algorithm [lzo] lz4 snappy
max_comp_streams 1
real 2.77s 2.63s 2.67s 2.85s 2.61s avg: 2.706s
user 0.01s 0.00s 0.00s 0.02s 0.00s
sys 0.51s 0.49s 0.49s 0.51s 0.46s
orig_data_size 48250880
compr_data_size 34759153 34759167 34759150 34759153 34759153 avg: 34759155
mem_used_total 35717120
comp_algorithm lzo [lz4] snappy
max_comp_streams 1
real 2.61s 2.61s 2.66s 2.65s 2.70s avg: 2.646s
user 0.01s 0.00s 0.01s 0.02s 0.01s
sys 0.44s 0.47s 0.51s 0.47s 0.52s
orig_data_size 48250880
compr_data_size 36489171 36489175 36489173 36489175 36489190 avg: 36489177
mem_used_total 37588992
######################----------------------TEST 4----------------------######################
~ # ./tmp/zramtest3.sh test4 /tmp/LatinIME.apk
lz0: 1.72s 1.73s 1.79s 1.70s 1.77s avg: 1.742s
lz4: 1.73s 1.74s 1.69s 1.67s 1.72s avg: 1.710s
N.B: The compr_data_size isn't different from the compr_data_size of the previous test.
######################--------------------SUMMARY----------------------######################
Total average time (4 test):
lzo: 8.664s (3.918+0.298+2.706+1.742)
lz4: 8.586s (3.922+0.308+2.646+1.710)
Gain: (664-586)/8664=0.9% (lz4 vs lzo)
Total average compressed size :
lzo: 99990186 (15235965+15235911+34759155*2)
lz4: 104187491 (15604609+15604528+36489177*2)
Gain: (104187491-99990186)/104187491=4% (lzo vs lz4)
#!/sbin/sh
sys_zram="/sys/block/zram0"
zram="/dev/block/zram0"
disksize="$((50*1024*1024))"
mnt_point="zram0mnt"
TEST_1="cp -f $2 /${mnt_point}"
reset(){
echo 1 > ${sys_zram}/reset
sleep 2
}
init_disk(){
mkdir -p ${mnt_point}
echo ${disksize} > ${sys_zram}/disksize
mke2fs -t ext4 -m 0 -I 128 -O ^has_journal,^ext_attr ${zram} >& /dev/null
mount -o noatime,barrier=0,data=writeback,nobh,discard ${zram} ${mnt_point}
cd ${mnt_point}
}
case $1 in
test1)
TEST="time tar xJf $2"
;;
test2)
TEST="time tar xf $2"
;;
test3)
TEST="time cp $2 ."
;;
test4)
TEST="${TEST_1}"
TEST_2="time cp -rf /${mnt_point}/ /tmp/"
;;
test5)
TEST="${TEST_1}"
TEST_2="time tar -xf /${mnt_point}/*.tar -C /tmp/"
;;
test6)
TEST="time ${TEST_1}"
TEST_2="time tar -xf /${mnt_point}/*.tar"
;;
*)
exit
;;
esac
benchmark(){
init_disk
${TEST} && ${TEST_2}
sync
sleep 5
echo 3 > /proc/sys/vm/drop_caches
sleep 5
if [ "$1" \< "test3" ] | [ "$1" = "test6" ]; then
echo -ne "orig_data_size\t" | cat - ${sys_zram}/orig_data_size
echo -ne "compr_data_size\t" | cat - ${sys_zram}/compr_data_size
echo -ne "mem_used_total\t" | cat - ${sys_zram}/mem_used_total
fi
cd ..
umount ${mnt_point}
reset
echo ""
}
streams_test(){
if [ -e ${sys_zram}/max_comp_streams ] && [ -n "$2" ] && [ "$2" != 0 ]; then
for i in $(seq 1 $2)
do
echo $i > ${sys_zram}/max_comp_streams
echo -ne "max_comp_streams\t" | cat - ${sys_zram}/max_comp_streams
benchmark $1
done
else
benchmark $1
fi
}
comp_algorithm(){
for c in $(cat ${sys_zram}/comp_algorithm | sed -e s#'\['#''#g -e s#'\]'#''#g)
do
echo $c > ${sys_zram}/comp_algorithm
echo -ne "\ncomp_algorithm\t" | cat - ${sys_zram}/comp_algorithm
streams_test $1 $2
done
}
echo -e "zram $1\t" $(date)
reset
if [ -e ${sys_zram}/comp_algorithm ]; then
comp_algorithm $1 $3
else
streams_test $1 $3
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment