Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Benchmarks #44

Open
flipkickmedia opened this issue Nov 28, 2020 · 10 comments
Open

Benchmarks #44

flipkickmedia opened this issue Nov 28, 2020 · 10 comments
Labels

Comments

@flipkickmedia
Copy link

flipkickmedia commented Nov 28, 2020

This script gives you a build for each flag and a benchmark sorted for each flag and with the -B option for an average over 30s. It excludes the first 10s of results. The mkp224o builds are copied into /usr/local/bin. Requires the bc command.

If you set the NO_CREATE env variable before you run the command it won't recreate the benchmark results
e.g.
NO_CREATE=1 ./benchmark.sh

If you set the NO_BUILD env variable it wont attempt to build mkp224o.
NO_BUILD=1 ./benchmark.sh

Output looks like:

root@localhost:~/mkp224o# ./benchmark.sh
Building mkp224o
already built /usr/local/bin/mkp224o-ref10
already built /usr/local/bin/mkp224o-amd64-51-30k
already built /usr/local/bin/mkp224o-amd64-64-24k
already built /usr/local/bin/mkp224o-donna
already built /usr/local/bin/mkp224o-donna-sse2
 done!

Creating benchmarks
--ref10 -s -T
--amd64-51-30k -s -T
--amd64-64-24k -s -T
--donna -s -T
--donna-sse2 -s -T
--ref10 -B -s -T
--amd64-51-30k -B -s -T
--amd64-64-24k -B -s -T
--donna -B -s -T
--donna-sse2 -B -s -T
done!

Calculating benchmark results............ done!

Results:
benchmark-mkp224o-ref10               2384301
benchmark-mkp224o-ref10-B             2587238
benchmark-mkp224o-donna-sse2          3622626
benchmark-mkp224o-donna-sse2-B        3656571
benchmark-mkp224o-amd64-51-30k        5726968
benchmark-mkp224o-amd64-51-30k-B      5789477
benchmark-mkp224o-donna               6015617
benchmark-mkp224o-donna-B             6201576
benchmark-mkp224o-amd64-64-24k        6444984
benchmark-mkp224o-amd64-64-24k-B      6508391

Script

#!/usr/bin/env bash

echo "Building mkp224o"

if [[ -z $NO_BUILD ]]; then
  if [[ ! -f /usr/local/bin/mkp224o-ref10 ]];then
    make clean; ./autogen.sh; ./configure --enable-ref10; make; cp mkp224o /usr/local/bin/mkp224o-ref10
  else
    echo "already built /usr/local/bin/mkp224o-ref10"
  fi

  if [[ ! -f /usr/local/bin/mkp224o-amd64-51-30k ]];then
    make clean; ./autogen.sh; ./configure --enable-amd64-51-30k; make; cp mkp224o /usr/local/bin/mkp224o-amd64-51-30k
  else
    echo "already built /usr/local/bin/mkp224o-amd64-51-30k"
  fi


  if [[ ! -f /usr/local/bin/mkp224o-amd64-64-24k ]];then
    make clean; ./autogen.sh; ./configure --enable-amd64-64-24k; make; cp mkp224o /usr/local/bin/mkp224o-amd64-64-24k
  else
    echo "already built /usr/local/bin/mkp224o-amd64-64-24k"
  fi


  if [[ ! -f /usr/local/bin/mkp224o-donna ]];then
    make clean; ./autogen.sh; ./configure --enable-donna; make; cp mkp224o /usr/local/bin/mkp224o-donna
  else
    echo "already built /usr/local/bin/mkp224o-donna"
  fi


  if [[ ! -f /usr/local/bin/mkp224o-donna-sse2 ]];then
    make clean; ./autogen.sh; ./configure --enable-donna-sse2; make; cp mkp224o /usr/local/bin/mkp224o-donna-sse2
  else
    echo "already built /usr/local/bin/mkp224o-donna-sse2"
  fi
fi

echo " done!"

if [[ -z $NO_CREATE ]];then
   echo "Creating benchmarks"
   echo "--ref10 -s -T"
  /usr/local/bin/mkp224o-ref10 -s -T benchmarkkeyhardtofind 2>&1 | head -n 8 | tail -n 3 > benchmark-mkp224o-ref10
  echo "--amd64-51-30k -s -T"
  /usr/local/bin/mkp224o-amd64-51-30k -s -T benchmarkkeyhardtofind 2>&1 | head -n 8 | tail -n 3 > benchmark-mkp224o-amd64-51-30k
  echo "--amd64-64-24k -s -T"
  /usr/local/bin/mkp224o-amd64-64-24k -s -T benchmarkkeyhardtofind 2>&1 | head -n 8 | tail -n 3 > benchmark-mkp224o-amd64-64-24k
  echo "--donna -s -T"
  /usr/local/bin/mkp224o-donna -s -T benchmarkkeyhardtofind 2>&1 | head -n 8 | tail -n 3 > benchmark-mkp224o-donna
  echo "--donna-sse2 -s -T"
  /usr/local/bin/mkp224o-donna-sse2 -s -T benchmarkkeyhardtofind 2>&1 | head -n 8 | tail -n 3 > benchmark-mkp224o-donna-sse2
  echo "--ref10 -B -s -T"
  /usr/local/bin/mkp224o-ref10 -B -s -T benchmarkkeyhardtofind 2>&1 | head -n 8 | tail -n 3 > benchmark-mkp224o-ref10-B
  echo "--amd64-51-30k -B -s -T"
  /usr/local/bin/mkp224o-amd64-51-30k -B -s -T benchmarkkeyhardtofind 2>&1 | head -n 8 | tail -n 3 > benchmark-mkp224o-amd64-51-30k-B
  echo "--amd64-64-24k -B -s -T"
  /usr/local/bin/mkp224o-amd64-64-24k -B -s -T benchmarkkeyhardtofind 2>&1 | head -n 8 | tail -n 3 > benchmark-mkp224o-amd64-64-24k-B
  echo "--donna -B -s -T"
  /usr/local/bin/mkp224o-donna -B -s -T benchmarkkeyhardtofind 2>&1 | head -n 8 | tail -n 3 > benchmark-mkp224o-donna-B
  echo "--donna-sse2 -B -s -T"
  /usr/local/bin/mkp224o-donna-sse2 -B -s -T benchmarkkeyhardtofind 2>&1 | head -n 8 | tail -n 3 > benchmark-mkp224o-donna-sse2-B
  echo "done!"
fi

echo -e
echo -n "Calculating benchmark results"

files=( benchmark-mkp224o-ref10 benchmark-mkp224o-amd64-51-30k benchmark-mkp224o-amd64-64-24k benchmark-mkp224o-donna benchmark-mkp224o-donna-sse2 benchmark-mkp224o-ref10-B benchmark-mkp224o-amd64-51-30k-B benchmark-mkp224o-amd64-64-24k-B benchmark-mkp224o-donna-B benchmark-mkp224o-donna-sse2-B)

IFS='
'
regex='^>calc/sec:([0-9]+\.[0-9]+).*'
values=()
for file in "${!files[@]}"; do
  for i in $(<${files[$file]}); do
    if [[ $i =~ $regex ]]; then
      values+=(${BASH_REMATCH[1]})
    fi
  done
  n="(${values[@]})/3"
  line="                                    "
  PROC_NAME=${files[$file]}
  calc=$(bc <<< "${n// /+}")
  line="${line:${#PROC_NAME}}"
  result=$(printf "%s %s %s" $PROC_NAME $line $calc)
  results+=("$result")
  values=()
  echo -n "."
done
echo " done!"

echo -e
echo "Results:"
mapfile -t sorted < <(printf "%s\n" "${results[@]}" | sort -r -k2,2n -k1,1)
for result in "${sorted[@]}"; do
  echo ${result}
done
@lilyanatia
Copy link

after replacing all the /usr/local/bin with ., this script works well and confirms what I already guessed would be the fastest on my hardware:

Results:
benchmark-mkp224o-ref10               35373783
benchmark-mkp224o-ref10-B             36767215
benchmark-mkp224o-donna-sse2          55913307
benchmark-mkp224o-donna-sse2-B        57579152
benchmark-mkp224o-donna               76592045
benchmark-mkp224o-donna-B             77199319
benchmark-mkp224o-amd64-51-30k        77893082
benchmark-mkp224o-amd64-51-30k-B      82166666
benchmark-mkp224o-amd64-64-24k        84535220
benchmark-mkp224o-amd64-64-24k-B      85214051

@flipkickmedia
Copy link
Author

The script could probably do with a little more error checking and also the ability to benchmark against some real search terms as these do impact the benchmarks quite significantly when you have a number of terms to search for. All this said the -B option is typically faster with my current searches (10 search terms, between 8-12 characters)

@cathugger
Copy link
Owner

The script could probably do with a little more error checking

correct.

and also the ability to benchmark against some real search terms as these do impact the benchmarks quite significantly when you have a number of terms to search for

keygen rate isn't significantly affected by search terms, unless the list is like really huge and linear search method is used which would start being slowdown at that point, or keys are being found at like really high rate in which case resets of keygen state would also start affecting performance. so idk if adding different search term stuff would affect much.

@waterrr
Copy link

waterrr commented Jul 26, 2021

Ubuntu20.04
i9-10980XE+128G DDR4

Results:
benchmark-mkp224o-ref10-B 37612746
benchmark-mkp224o-ref10 37744107
benchmark-mkp224o-donna-sse2 59914373
benchmark-mkp224o-donna-sse2-B 68708351
benchmark-mkp224o-amd64-51-30k-B 92619635
benchmark-mkp224o-amd64-51-30k 92920878
benchmark-mkp224o-donna-B 96342484
benchmark-mkp224o-donna 104819271
benchmark-mkp224o-amd64-64-24k-B 106678425
benchmark-mkp224o-amd64-64-24k 116345680

@cculianu
Copy link

cculianu commented Dec 3, 2021

I cleaned the script up a little bit to use loops and be easier to modify, and to not leave lots of files in the top-level dir.

I also adapted it to work on a macOS Big Sur system. I am pasting it here in case anybody else wants it. It also still works on Linux (but you have to comment-out the macOS stuff and uncomment the Linux stuff at top of file).

Results:

mkp224o-ref10-B 9082180
mkp224o-ref10 14227022
mkp224o-donna-sse2-B 16022995
mkp224o-donna-B 20340496
mkp224o-donna-sse2 20486281
mkp224o-donna 26037248
#!/usr/bin/env bash

set -e

BINDIR=`pwd`/bin
BENCHDIR=`pwd`/benchmarks
#Uncomment for Linux:
#FLAGS="ref10 amd64-51-30k amd64-64-24k donna donna-sse2"
#libdir="/usr/local/lib"
#includedir="/usr/local/include"

#Below is for macOS Big Sur with MacPorts, comment it out if on Linux
FLAGS="ref10 donna donna-sse2"
libdir="/opt/local/lib"
includedir="/opt/local/include"


if [[ -z $NO_BUILD ]]; then
    echo "Building mkp224o"
    mkdir -p "$BINDIR"
    for flag in $FLAGS; do
        OUTFILE="${BINDIR}"/mkp224o-"$flag"
        if [[ ! -f "$OUTFILE" ]]; then
            make clean
            ./autogen.sh
            CFLAGS="-fomit-frame-pointer -O3 -I${includedir}" LDFLAGS="-L${libdir}" \
                ./configure --enable-"${flag}"
            make
            cp -fpv mkp224o "$OUTFILE"
        else
            echo "already built $OUTFILE"
        fi
    done
    echo " done!"
fi


files=""

if [[ -z $NO_CREATE ]]; then
    echo "Creating benchmarks"
    mkdir -p "$BENCHDIR"
    rm -fv "$BENCHDIR"/mkp224o*
fi
for flag in $FLAGS; do
    [[ -z $NO_CREATE ]] && echo "--${flag} -s -T"
    [[ -z $NO_CREATE ]] && "$BINDIR"/mkp224o-"$flag" -s -T benchmarkkeyhardtofind 2>&1 | head -n 8 | tail -n 3 > "$BENCHDIR"/mkp224o-"$flag"
    files="${files} $BENCHDIR/mkp224o-${flag}"
done
for flag in $FLAGS; do
    [[ -z $NO_CREATE ]] && echo "--${flag} -B -s -T"
    [[ -z $NO_CREATE ]] && "$BINDIR"/mkp224o-"$flag" -B -s -T benchmarkkeyhardtofind 2>&1 | head -n 8 | tail -n 3 > "$BENCHDIR"/mkp224o-"$flag"-B
    files="${files} $BENCHDIR/mkp224o-${flag}-B"
done
[[ -z $NO_CREATE ]] && echo "done!"

echo -n "Calculating benchmark results"

regex='^>calc/sec:([0-9]+\.[0-9]+).*'
values=()
for file in $files; do
    for i in $(cat "$file"); do
        if [[ $i =~ $regex ]]; then
            values+=(${BASH_REMATCH[1]})
        fi
    done
    n="(${values[@]})/3"
    line="                                    "
    BASE_NAME=$(basename $file)
    calc=$(bc <<< "${n// /+}")
    line="${line:${#file}}"
    result=$(printf "%s %s %s" $BASE_NAME $line $calc)
    results+=("$result")
    values=()
    echo -n "."
done
echo " done!"

echo -e
echo "Results:"
mapfile -t sorted < <(printf "%s\n" "${results[@]}" | sort -r -k2,2n -k1,1)
for result in "${sorted[@]}"; do
    echo ${result}
done

@ghost
Copy link

ghost commented Dec 9, 2021

Would love to see a windows version of this :)

@cculianu
Copy link

I can try and hack it to work on windows but with mingw & bash probably.. since.. well .. powershell is beyond my capabilities.

@ghost
Copy link

ghost commented Dec 10, 2021

I can try and hack it to work on windows but with mingw & bash probably.. since.. well .. powershell is beyond my capabilities.

That's perfectly fine, I'd appreciate that!

@milahu
Copy link

milahu commented Oct 1, 2022

#! /usr/bin/env bash

# mkp224o-benchmark.sh - a benchmarking wrapper for mkp224o

# print live stats in a pretty format

# loop different binaries and extra_options
# to find the fastest combination

# MIT license

# select range of samples
samples_from=1; samples_to=5 # slow
samples_from=1; samples_to=1 # too fast. shows speed 0 for some commands
samples_from=2; samples_to=2 # show only the second sample

extra_options_list=()
#extra_options_list+=("")
extra_options_list+=("-B")

set -e

bindir=$(dirname $(which mkp224o-donna)) # also works on nixos linux

printf "# args:"; for arg in "$@"; do printf " %q" "$arg"; done; echo
echo -e "# speed\tround\tsample\tcommand"

round_num=0
while true
do
  round_num=$((round_num + 1))
  for bin in $bindir/mkp224o-*
  do
    binname=$(basename $bin)
    if [[ $# == 0 ]]
    then
      $bin -h # show help
      echo
      echo "$(basename "$0"): hint: run this script with extra_options: -qxs"
      echo "$(basename "$0"): hint: pipe the output through: | tee -a stats.txt"
      exit 1
    fi
    for extra_options in "${extra_options_list[@]}"
    do
      command="$binname"
      [[ "$extra_options" != "" ]] && command+=" $extra_options"
      sample_num=0
      while read line
      do
        speed=$(echo "$line" | sed -E "s/^>calc\/sec:([0-9]+)\..*$/\1/")
        if [[ "$speed" == "" ]]; then echo "# $line"; continue; fi
        sample_num=$((sample_num + 1))
        (( sample_num < samples_from )) && continue
        echo -e "${speed}\t${round_num}\t${sample_num}\t${command}"
        (( sample_num >= samples_to )) && break # stop the binary
      done < <(
        # run the binary
        $bin "$@" $extra_options 2>&1
      )
    done
  done
done

example output

4 core x 2.5 GHz Intel Core i5

# speed round   sample  command
1198801 1       2       mkp224o-amd64-51-30k -B
717167  1       2       mkp224o-amd64-64-20k -B
597282  1       2       mkp224o-donna -B
373615  1       2       mkp224o-donna-sse2 -B
283938  1       2       mkp224o-ref10 -B
387220  2       2       mkp224o-amd64-51-30k -B
303739  2       2       mkp224o-amd64-64-20k -B
347268  2       2       mkp224o-donna -B
290095  2       2       mkp224o-donna-sse2 -B
265664  2       2       mkp224o-ref10 -B
623069  3       2       mkp224o-amd64-51-30k -B
599756  3       2       mkp224o-amd64-64-20k -B
462099  3       2       mkp224o-donna -B
291557  3       2       mkp224o-donna-sse2 -B
252223  3       2       mkp224o-ref10 -B

128 core x 2.9 GHz AMD Ryzen

# speed round   sample  command
273909970       1       1       mkp224o-amd64-51-30k -B
262588670       1       2       mkp224o-amd64-51-30k -B
262215078       1       3       mkp224o-amd64-51-30k -B
262100553       1       4       mkp224o-amd64-51-30k -B
261988668       1       5       mkp224o-amd64-51-30k -B
261904180       1       6       mkp224o-amd64-51-30k -B
261788871       1       7       mkp224o-amd64-51-30k -B
261755834       1       8       mkp224o-amd64-51-30k -B
261654566       1       9       mkp224o-amd64-51-30k -B
130280939       1       1       mkp224o-amd64-64-20k -B
181521769       1       2       mkp224o-amd64-64-20k -B
351326946       1       3       mkp224o-amd64-64-20k -B
351467313       1       4       mkp224o-amd64-64-20k -B
351311962       1       5       mkp224o-amd64-64-20k -B
351345975       1       6       mkp224o-amd64-64-20k -B
351526912       1       7       mkp224o-amd64-64-20k -B
351447120       1       8       mkp224o-amd64-64-20k -B
351364292       1       9       mkp224o-amd64-64-20k -B
111961781       1       1       mkp224o-donna -B
134591413       1       2       mkp224o-donna -B
281993414       1       3       mkp224o-donna -B
281819835       1       4       mkp224o-donna -B
281802496       1       5       mkp224o-donna -B
281561613       1       6       mkp224o-donna -B
281408269       1       7       mkp224o-donna -B
281553831       1       8       mkp224o-donna -B
281403727       1       9       mkp224o-donna -B
78285771        1       1       mkp224o-donna-sse2 -B
75914242        1       2       mkp224o-donna-sse2 -B
139051566       1       3       mkp224o-donna-sse2 -B
139062682       1       4       mkp224o-donna-sse2 -B
139003723       1       5       mkp224o-donna-sse2 -B
138812043       1       6       mkp224o-donna-sse2 -B
138818565       1       7       mkp224o-donna-sse2 -B
138772269       1       8       mkp224o-donna-sse2 -B
138734632       1       9       mkp224o-donna-sse2 -B
35798756        1       1       mkp224o-ref10 -B
62065630        1       2       mkp224o-ref10 -B
119136297       1       3       mkp224o-ref10 -B
119141126       1       4       mkp224o-ref10 -B
119157332       1       5       mkp224o-ref10 -B
119116997       1       6       mkp224o-ref10 -B
119094422       1       7       mkp224o-ref10 -B
119074651       1       8       mkp224o-ref10 -B
119038555       1       9       mkp224o-ref10 -B

@AaronBeier
Copy link

Arch Linux, Ryzen 9 9900X, numbers averaged over 10 seconds, compiled with -flto=auto -O3 -march=native

--enable-donna
117.197.262 c/s

--enable-donna-sse2
90.019.020 c/s

--enable-ref10
41.197.252 c/s

--enable-amd64-51-30k
116.137.700 c/s

--enable-amd64-64-24k
143.657.351 c/s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants