Skip to content

Commit eb59b6e

Browse files
committed
Add -nowrite arg to TJBench to improve consistency
Prevents any images from being written to disk, thus making the performance of the benchmark as CPU-bound as possible.
1 parent 368cd52 commit eb59b6e

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

ChangeLog.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ Since the macro is used only internally, it has been moved into jconfigint.h.
5252
JSIMD_FORCENONE environment variable to 1 (the other SIMD implementations
5353
already had this capability.)
5454

55+
[11] Added a new command-line argument to TJBench (-nowrite) that prevents the
56+
benchmark from outputting any images. This removes any potential operating
57+
system overhead that might be caused by lazy writes to disk and thus improves
58+
the consistency of the performance measurements.
59+
5560

5661
1.4.2
5762
=====

java/TJBench.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C)2009-2014 D. R. Commander. All Rights Reserved.
2+
* Copyright (C)2009-2014, 2016 D. R. Commander. All Rights Reserved.
33
*
44
* Redistribution and use in source and binary forms, with or without
55
* modification, are permitted provided that the following conditions are met:
@@ -35,7 +35,7 @@
3535
class TJBench {
3636

3737
static int flags = 0, quiet = 0, pf = TJ.PF_BGR, yuvpad = 1, warmup = 1;
38-
static boolean compOnly, decompOnly, doTile, doYUV;
38+
static boolean compOnly, decompOnly, doTile, doYUV, write;
3939

4040
static final String[] pixFormatStr = {
4141
"RGB", "BGR", "RGBX", "BGRX", "XBGR", "XRGB", "GRAY"
@@ -223,6 +223,8 @@ else if (quiet != 2)
223223
}
224224
}
225225

226+
if (!write) return;
227+
226228
if (sf.getNum() != 1 || sf.getDenom() != 1)
227229
sizeStr = new String(sf.getNum() + "_" + sf.getDenom());
228230
else if (tilew != w || tileh != h)
@@ -394,7 +396,7 @@ static void fullTest(byte[] srcBuf, int w, int h, int subsamp, int jpegQual,
394396
System.out.format(" Output bit stream: %f Megabits/sec\n",
395397
(double)totalJpegSize * 8. / 1000000. * (double)iter / elapsed);
396398
}
397-
if (tilew == w && tileh == h) {
399+
if (tilew == w && tileh == h && write) {
398400
String tempStr = fileName + "_" + subName[subsamp] + "_" + "Q" +
399401
jpegQual + ".jpg";
400402
FileOutputStream fos = new FileOutputStream(tempStr);
@@ -659,7 +661,9 @@ else if (nsf > 2) {
659661
System.out.println("-benchtime <t> = Run each benchmark for at least <t> seconds (default = 5.0)");
660662
System.out.println("-warmup <w> = Execute each benchmark <w> times to prime the cache before");
661663
System.out.println(" taking performance measurements (default = 1)");
662-
System.out.println("-componly = Stop after running compression tests. Do not test decompression.\n");
664+
System.out.println("-componly = Stop after running compression tests. Do not test decompression.");
665+
System.out.println("-nowrite = Do not write reference or output images (improves consistency");
666+
System.out.println(" of performance measurements.)\n");
663667
System.out.println("NOTE: If the quality is specified as a range (e.g. 90-100), a separate");
664668
System.out.println("test will be performed for all quality values in the range.\n");
665669
System.exit(1);
@@ -817,6 +821,8 @@ else if (argv[i].equals("411"))
817821
}
818822
if (argv[i].equalsIgnoreCase("-componly"))
819823
compOnly = true;
824+
if (argv[i].equalsIgnoreCase("-nowrite"))
825+
write = false;
820826
if (argv[i].equalsIgnoreCase("-warmup") && i < argv.length - 1) {
821827
int temp = -1;
822828
try {

tjbench.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C)2009-2015 D. R. Commander. All Rights Reserved.
2+
* Copyright (C)2009-2016 D. R. Commander. All Rights Reserved.
33
*
44
* Redistribution and use in source and binary forms, with or without
55
* modification, are permitted provided that the following conditions are met:
@@ -46,7 +46,7 @@
4646
#define _throwbmp(m) _throw(m, bmpgeterr())
4747

4848
int flags=TJFLAG_NOREALLOC, componly=0, decomponly=0, doyuv=0, quiet=0,
49-
dotile=0, pf=TJPF_BGR, yuvpad=1, warmup=1;
49+
dotile=0, pf=TJPF_BGR, yuvpad=1, warmup=1, write=1;
5050
char *ext="ppm";
5151
const char *pixFormatStr[TJ_NUMPF]=
5252
{
@@ -224,7 +224,7 @@ int decomp(unsigned char *srcbuf, unsigned char **jpegbuf,
224224
snprintf(tempstr, 1024, "%s_%s%s_%s.%s", filename, subName[subsamp],
225225
qualstr, sizestr, ext);
226226

227-
if(savebmp(tempstr, dstbuf, scaledw, scaledh, pf,
227+
if(write && savebmp(tempstr, dstbuf, scaledw, scaledh, pf,
228228
(flags&TJFLAG_BOTTOMUP)!=0)==-1)
229229
_throwbmp("saving bitmap");
230230
ptr=strrchr(tempstr, '.');
@@ -259,7 +259,7 @@ int decomp(unsigned char *srcbuf, unsigned char **jpegbuf,
259259
dstbuf[pitch*row+col]
260260
=abs(dstbuf[pitch*row+col]-srcbuf[pitch*row+col]);
261261
}
262-
if(savebmp(tempstr, dstbuf, w, h, pf,
262+
if(write && savebmp(tempstr, dstbuf, w, h, pf,
263263
(flags&TJFLAG_BOTTOMUP)!=0)==-1)
264264
_throwbmp("saving bitmap");
265265
}
@@ -422,7 +422,7 @@ int fullTest(unsigned char *srcbuf, int w, int h, int subsamp, int jpegqual,
422422
printf(" Output bit stream: %f Megabits/sec\n",
423423
(double)totaljpegsize*8./1000000.*(double)iter/elapsed);
424424
}
425-
if(tilew==w && tileh==h)
425+
if(tilew==w && tileh==h && write)
426426
{
427427
snprintf(tempstr, 1024, "%s_%s_Q%d.jpg", filename, subName[subsamp],
428428
jpegqual);
@@ -756,7 +756,9 @@ void usage(char *progname)
756756
printf("-benchtime <t> = Run each benchmark for at least <t> seconds (default = 5.0)\n");
757757
printf("-warmup <w> = Execute each benchmark <w> times to prime the cache before\n");
758758
printf(" taking performance measurements (default = 1)\n");
759-
printf("-componly = Stop after running compression tests. Do not test decompression.\n\n");
759+
printf("-componly = Stop after running compression tests. Do not test decompression.\n");
760+
printf("-nowrite = Do not write reference or output images (improves consistency of\n");
761+
printf(" performance measurements.)\n\n");
760762
printf("NOTE: If the quality is specified as a range (e.g. 90-100), a separate\n");
761763
printf("test will be performed for all quality values in the range.\n\n");
762764
exit(1);
@@ -906,6 +908,7 @@ int main(int argc, char *argv[])
906908
}
907909
}
908910
if(!strcasecmp(argv[i], "-componly")) componly=1;
911+
if(!strcasecmp(argv[i], "-nowrite")) write=0;
909912
}
910913
}
911914

0 commit comments

Comments
 (0)