Skip to content

Commit

Permalink
Better adaptive adjustment of the number of loop iterations
Browse files Browse the repository at this point in the history
Keep doubling the number of loop iterations until the duration
of test run exceeds 0.5s and also start from 1 loop iteration
instead of 16. In the case if the memory bandwidth is extremely
low (for example, running tests with the framebuffer), it makes
the test duration reasonable. Also in the case if the memory
bandwidth is extremely high, this approach reduces the periodic
gettimeofday() calls overhead.
  • Loading branch information
ssvb committed Mar 30, 2016
1 parent 05d03c7 commit 21b4a91
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@

#define SIZE (32 * 1024 * 1024)
#define BLOCKSIZE 2048
#define COUNT 16
#define MAXREPEATS 10

#ifdef BENCH_FRAMEBUFFER
Expand Down Expand Up @@ -74,7 +73,7 @@ static double bandwidth_bench_helper(int64_t *dstbuf, int64_t *srcbuf,
void (*f)(int64_t *, int64_t *, int),
const char *description)
{
int i, j, loopcount, n;
int i, j, loopcount, innerloopcount, n;
double t1, t2;
double speed, maxspeed;
double s, s0, s1, s2;
Expand All @@ -86,13 +85,14 @@ static double bandwidth_bench_helper(int64_t *dstbuf, int64_t *srcbuf,
{
f(dstbuf, srcbuf, size);
loopcount = 0;
innerloopcount = 1;
t1 = gettime();
do
{
loopcount++;
loopcount += innerloopcount;
if (use_tmpbuf)
{
for (i = 0; i < COUNT; i++)
for (i = 0; i < innerloopcount; i++)
{
for (j = 0; j < size; j += blocksize)
{
Expand All @@ -103,14 +103,15 @@ static double bandwidth_bench_helper(int64_t *dstbuf, int64_t *srcbuf,
}
else
{
for (i = 0; i < COUNT; i++)
for (i = 0; i < innerloopcount; i++)
{
f(dstbuf, srcbuf, size);
}
}
innerloopcount *= 2;
t2 = gettime();
} while (t2 - t1 < 0.5);
speed = (double)size * COUNT * loopcount / (t2 - t1) / 1000000.;
speed = (double)size * loopcount / (t2 - t1) / 1000000.;

s0 += 1;
s1 += speed;
Expand Down

0 comments on commit 21b4a91

Please sign in to comment.