Skip to content

Instantly share code, notes, and snippets.

@jarikomppa
Created April 1, 2021 07:12
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 jarikomppa/b8b8e65ee41b0ac5e70b812710d74660 to your computer and use it in GitHub Desktop.
Save jarikomppa/b8b8e65ee41b0ac5e70b812710d74660 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <chrono>
double payload(int w, int h, int iters)
{
float xscale, yscale, zx, zy, cx, tempx, cy;
int x, y, i, j;
int maxx, maxy, count;
maxx = w;
maxy = h;
xscale = 1;
yscale = 1;
double sum = 0;
for (y = 1; y <= maxy - 1; y++) {
for (x = 1; x <= maxx - 1; x++)
{
cx = x * xscale;
cy = y * yscale;
zx = 0;
zy = 0;
count = 0;
while ((zx * zx + zy * zy < 4) && (count < iters))
{
tempx = zx * zx - zy * zy + cx;
zy = 2 * zx * zy + cy;
zx = tempx;
count = count + 1;
}
sum += count;
}
}
return sum;
}
volatile double fool;
long long test()
{
auto start = std::chrono::high_resolution_clock::now();
fool = payload(250, 250, 100);
auto end = std::chrono::high_resolution_clock::now();
auto dur = end - start;
return std::chrono::duration_cast<std::chrono::microseconds>(dur).count();
}
long long samples[10000];
int main()
{
int idx = 0;
long long sum = 0;
long long mn = test();
long long mx = test();
int reset = 10000;
while (1)
{
long long v = test();
if (v < mn) mn = v;
if (v > mx) mx = v;
sum -= samples[idx];
samples[idx] = v;
sum += v;
idx = (idx + 1) % 10000;
printf("\rcur:%4llu avg:%4llu min:%4llu max:%4llu delta:%4llu ", v, sum / 10000, mn, mx, mx-mn);
reset--;
if (!reset)
{
printf("\n");
mn = mx = v;
reset = 10000;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment