Last active
October 19, 2019 04:55
-
-
Save lastcoolnameleft/ee32e09357c061a64425b0745590ca9f to your computer and use it in GitHub Desktop.
Code Generation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/earthgecko/3089509