Skip to content

Instantly share code, notes, and snippets.

@iax7
Created April 23, 2020 19:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save iax7/0f25308f2c9e42081459979f77d91365 to your computer and use it in GitHub Desktop.
Save iax7/0f25308f2c9e42081459979f77d91365 to your computer and use it in GitHub Desktop.
#!/bin/env bash
# https://www.lastdragon.net/?p=2260
cat > programa.c << EOF
#include <stdio.h>
double powern(double d, unsigned n)
{
double x = 1.0;
unsigned j;
for (j = 1; j <= n; j++)
x *= d;
return x;
}
int main(void)
{
double sum = 0.0;
unsigned i;
for (i = 1; i <= 1000000000; i++)
{
sum += powern (i, i % 5);
}
printf ("sum = %g\n", sum);
return 0;
}
EOF
echo "Compilando y ejecutando sin optimizacion"
gcc -Wall -O0 programa.c -lm -o programa
ls -l programa
time ./programa
rm -f programa
echo ""
echo "Compilando y Optimizando nivel 1"
gcc -Wall -O1 programa.c -lm -o programa
ls -l programa
time ./programa
rm -f programa
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment