Skip to content

Instantly share code, notes, and snippets.

@lastcoolnameleft
Last active October 19, 2019 04:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lastcoolnameleft/ee32e09357c061a64425b0745590ca9f to your computer and use it in GitHub Desktop.
Save lastcoolnameleft/ee32e09357c061a64425b0745590ca9f to your computer and use it in GitHub Desktop.
Code Generation
gen_random() {
NUM=$1
if [ $(($NUM%1000000)) -eq 0 ]; then
echo $NUM
fi
RAND=$(head /dev/urandom | tr -dc 'A-Za-z0-9!"#$%&'\''()*+,-./:;<=>?@[\]^_`{|}~\n\t' | head -c100)
echo "$RAND" | gcc -x c - > /dev/null 2>&1
RESULT=$?
if [ $RESULT -eq 0 ]; then
echo 'SUCCESSFULLY COMPILED!' $NUM
echo "$RAND"
fi
}
export -f gen_random
run_serial() {
a=0
COUNT=$1
while [ $a -lt $COUNT ]
do
a=`expr $a + 1`
gen_random $a
done
}
export -f run_serial
$ time seq 1000 | parallel gen_random
...
real 0m12.335s
user 0m12.940s
sys 0m10.225s
$ time seq 4 | parallel -j+0 run_serial 250
...
real 0m4.361s
user 0m10.485s
sys 0m5.698s
time seq 4 | parallel -j+0 run_serial 10000000
sudo apt update
sudo apt install -y build-essential
sudo mkdir /mnt/ramdisk
sudo mount -t tmpfs -o rw,size=1G tmpfs /mnt/ramdisk
cd /mnt/ramdisk
@lastcoolnameleft
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment