diff options
author | Tor Andersson <tor@ghostscript.com> | 2008-03-21 00:15:40 +0100 |
---|---|---|
committer | Tor Andersson <tor@ghostscript.com> | 2008-03-21 00:15:40 +0100 |
commit | 51fbd6bc9ed5e86170f292615e037fdd7f3678e2 (patch) | |
tree | 1b1e05ac655ebd76a3bc4a76ec504c9815c9fb67 /apps | |
parent | 224fa898b48693e0c82c86da254e8914b5808bec (diff) | |
download | mupdf-51fbd6bc9ed5e86170f292615e037fdd7f3678e2.tar.xz |
Added benchmark for rasterization.
Diffstat (limited to 'apps')
-rw-r--r-- | apps/pdftool.c | 166 |
1 files changed, 139 insertions, 27 deletions
diff --git a/apps/pdftool.c b/apps/pdftool.c index cbb573b7..ce0380ee 100644 --- a/apps/pdftool.c +++ b/apps/pdftool.c @@ -12,6 +12,8 @@ #include "fitz.h" #include "mupdf.h" +#include <sys/time.h> + /* * Common operations. * Parse page selectors. @@ -433,14 +435,25 @@ cleanmain(int argc, char **argv) enum { DRAWPNM, DRAWTXT, DRAWXML }; +struct benchmark +{ + int pages; + long min; + int minpage; + long avg; + long max; + int maxpage; +}; + fz_renderer *drawgc = nil; int drawmode = DRAWPNM; -char *drawpattern = "out%0.3d.pnm"; +char *drawpattern = nil; pdf_page *drawpage = nil; float drawzoom = 1.0; int drawrotate = 0; int drawbands = 1; int drawcount = 0; +int benchmark = 0; void drawusage(void) @@ -453,27 +466,70 @@ drawusage(void) " -r -\tresolution in dpi\n" " -t \tutf-8 text output instead of graphics\n" " -x \txml dump of display tree\n" + " -m \tprint benchmark results\n" " example:\n" " pdftool draw -o out%%0.3d.pnm a.pdf 1-3,5,9-\n"); exit(1); } void -drawloadpage(int pagenum) +gettime(long *time_) +{ + struct timeval tv; + + if (gettimeofday(&tv, NULL) < 0) + abort(); + + *time_ = tv.tv_sec * 1000000 + tv.tv_usec; +} + +void +drawloadpage(int pagenum, struct benchmark *loadtimes) { fz_error *error; fz_obj *pageobj; + long start; + long end; + long elapsed; + + fprintf(stderr, "draw %s page %d ", srcname, pagenum); + if (benchmark && loadtimes) + { + fflush(stderr); + gettime(&start); + } pageobj = pdf_getpageobject(srcpages, pagenum - 1); error = pdf_loadpage(&drawpage, src, pageobj); if (error) die(error); - fprintf(stderr, "draw %s page %d mediabox [ %g %g %g %g ] rotate %d\n", - srcname, pagenum, + if (benchmark && loadtimes) + { + gettime(&end); + elapsed = end - start; + + if (elapsed < loadtimes->min) + { + loadtimes->min = elapsed; + loadtimes->minpage = pagenum; + } + if (elapsed > loadtimes->max) + { + loadtimes->max = elapsed; + loadtimes->maxpage = pagenum; + } + loadtimes->avg += elapsed; + loadtimes->pages++; + } + + fprintf(stderr, "mediabox [ %g %g %g %g ] rotate %d%s", drawpage->mediabox.x0, drawpage->mediabox.y0, drawpage->mediabox.x1, drawpage->mediabox.y1, - drawpage->rotate); + drawpage->rotate, + benchmark ? "" : "\n"); + if (benchmark) + fflush(stderr); } void @@ -484,7 +540,7 @@ drawfreepage(void) } void -drawpnm(int pagenum) +drawpnm(int pagenum, struct benchmark *loadtimes, struct benchmark *drawtimes) { fz_error *error; fz_matrix ctm; @@ -494,8 +550,14 @@ drawpnm(int pagenum) char buf[256]; int x, y, w, h, b, bh; int fd; + long start; + long end; + long elapsed; + + drawloadpage(pagenum, loadtimes); - drawloadpage(pagenum); + if (benchmark) + gettime(&start); ctm = fz_identity(); ctm = fz_concat(ctm, fz_translate(0, -drawpage->mediabox.y1)); @@ -513,12 +575,10 @@ drawpnm(int pagenum) fd = open(namebuf, O_BINARY|O_WRONLY|O_CREAT|O_TRUNC, 0666); if (fd < 0) die(fz_throw("ioerror: could not open file '%s'", namebuf)); - } - else - fd = 1; - sprintf(buf, "P6\n%d %d\n255\n", w, h); - write(fd, buf, strlen(buf)); + sprintf(buf, "P6\n%d %d\n255\n", w, h); + write(fd, buf, strlen(buf)); + } error = fz_newpixmap(&pix, bbox.x0, bbox.y0, w, bh, 4); if (error) @@ -535,21 +595,24 @@ drawpnm(int pagenum) if (error) die(error); - for (y = 0; y < pix->h; y++) + if (drawpattern) { - unsigned char *src = pix->samples + y * pix->w * 4; - unsigned char *dst = src; - - for (x = 0; x < pix->w; x++) + for (y = 0; y < pix->h; y++) { - dst[x * 3 + 0] = src[x * 4 + 1]; - dst[x * 3 + 1] = src[x * 4 + 2]; - dst[x * 3 + 2] = src[x * 4 + 3]; - } + unsigned char *src = pix->samples + y * pix->w * 4; + unsigned char *dst = src; - write(fd, dst, pix->w * 3); + for (x = 0; x < pix->w; x++) + { + dst[x * 3 + 0] = src[x * 4 + 1]; + dst[x * 3 + 1] = src[x * 4 + 2]; + dst[x * 3 + 2] = src[x * 4 + 3]; + } - memset(src, 0xff, pix->w * 4); + write(fd, dst, pix->w * 3); + + memset(src, 0xff, pix->w * 4); + } } pix->y += bh; @@ -563,6 +626,28 @@ drawpnm(int pagenum) close(fd); drawfreepage(); + + if (benchmark) + { + gettime(&end); + elapsed = end - start; + + if (elapsed < drawtimes->min) + { + drawtimes->min = elapsed; + drawtimes->minpage = pagenum; + } + if (elapsed > drawtimes->max) + { + drawtimes->max = elapsed; + drawtimes->maxpage = pagenum; + } + drawtimes->avg += elapsed; + drawtimes->pages++; + + fprintf(stderr, " time %.3fs\n", + elapsed / 1000000.0); + } } void @@ -572,7 +657,7 @@ drawtxt(int pagenum) pdf_textline *line; fz_matrix ctm; - drawloadpage(pagenum); + drawloadpage(pagenum, NULL); ctm = fz_concat( fz_translate(0, -drawpage->mediabox.y1), @@ -591,7 +676,7 @@ drawtxt(int pagenum) void drawxml(int pagenum) { - drawloadpage(pagenum); + drawloadpage(pagenum, NULL); fz_debugtree(drawpage->tree); drawfreepage(); } @@ -601,10 +686,17 @@ drawpages(char *pagelist) { int page, spage, epage; char *spec, *dash; + struct benchmark loadtimes, drawtimes; if (!src) drawusage(); + if (benchmark) + { + memset(&loadtimes, 0x00, sizeof (loadtimes)); + memset(&drawtimes, 0x00, sizeof (drawtimes)); + } + spec = strsep(&pagelist, ","); while (spec) { @@ -630,9 +722,10 @@ drawpages(char *pagelist) { if (page < 1 || page > pdf_getpagecount(srcpages)) continue; + switch (drawmode) { - case DRAWPNM: drawpnm(page); break; + case DRAWPNM: drawpnm(page, &loadtimes, &drawtimes); break; case DRAWTXT: drawtxt(page); break; case DRAWXML: drawxml(page); break; } @@ -640,6 +733,24 @@ drawpages(char *pagelist) spec = strsep(&pagelist, ","); } + + if (benchmark) + { + if (loadtimes.pages > 0) + { + loadtimes.avg /= loadtimes.pages; + drawtimes.avg /= drawtimes.pages; + + printf("benchmark[load]: min: %6.3fs (page % 4d), avg: %6.3fs, max: %6.3f (page % 4d)\n", + loadtimes.min / 1000000.0, loadtimes.minpage, + loadtimes.avg / 1000000.0, + loadtimes.max / 1000000.0, loadtimes.maxpage); + printf("benchmark[draw]: min: %6.3fs (page % 4d), avg: %6.3fs, max: %6.3f (page % 4d)\n", + drawtimes.min / 1000000.0, drawtimes.minpage, + drawtimes.avg / 1000000.0, + drawtimes.max / 1000000.0, drawtimes.maxpage); + } + } } void @@ -649,7 +760,7 @@ drawmain(int argc, char **argv) char *password = ""; int c; - while ((c = getopt(argc, argv, "b:d:o:r:tx")) != -1) + while ((c = getopt(argc, argv, "b:d:o:r:txm")) != -1) { switch (c) { @@ -659,6 +770,7 @@ drawmain(int argc, char **argv) case 'r': drawzoom = atof(optarg) / 72.0; break; case 't': drawmode = DRAWTXT; break; case 'x': drawmode = DRAWXML; break; + case 'm': benchmark = 1; break; default: drawusage(); break; |