Skip to content

Instantly share code, notes, and snippets.

@SegHaxx
Created May 9, 2025 07:59
Show Gist options
  • Save SegHaxx/99c4c2ad06ccdc15949298ef44a58ed8 to your computer and use it in GitHub Desktop.
Save SegHaxx/99c4c2ad06ccdc15949298ef44a58ed8 to your computer and use it in GitHub Desktop.
Minimalist floating point mandelbrot benchmark
#include <stdio.h>
#include <time.h>
// "0123 456789ABCDEF";
char gradient[]=".,-=\"^!:;x+X$#&@";
static void mandel(
int w, int h,
float cx0, float cy0,
float cx1, float cy1
){
float x,y,x0,y0,x2,y2;
int px,py,i;
char c;
float sx=(cx1-cx0)/(float)w;
float sy=(cy1-cy0)/(float)h;
y0=cy0-(sy*.5);
for(py=0; py<h;++py){
//puts("");
fflush(stdout);
x0=cx0;
y0+=sy;
for(px=0; px<w;++px){
x0+=sx;
x=0,y=0,x2=0,y2=0;
for(i=0;i<256;++i){
y=(x+x)*y+y0;
x=x2-y2+x0;
x2=x*x;
y2=y*y;
if(x2+y2>4){
i=i&0xf;
c=gradient[i];
goto out;
}
}
c=' ';
out:
putchar(c);
//fflush(stdout);
}
}
getchar();
//puts("");
}
int main(int argc,char* argv[]){
clock_t ticks=clock();
mandel(80, 25, -2.05, -1.0, 0.6, 1.0);
ticks=clock()-ticks;
printf("%f sec\n",(float)ticks/CLOCKS_PER_SEC);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment