[LLVMbugs] [Bug 5165] New: npoly benchmark

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Sat Oct 10 15:50:41 PDT 2009


http://llvm.org/bugs/show_bug.cgi?id=5165

           Summary: npoly benchmark
           Product: new-bugs
           Version: 2.5
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Keywords: code-quality
          Severity: normal
          Priority: P2
         Component: new bugs
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: bearophile at mailas.com
                CC: llvmbugs at cs.uiuc.edu


This is a small benchmark written in C. nicholas on #llvm has said "feel free
to file it in bugzilla for further analysis".

I think this is the origin of this benchmark:
http://openmap.bbn.com/~kanderso/performance/postscript/in-poly.ps

I have cleaned up a little the C code:

// C code, npoly.c
#include "stdio.h"

// return true if (x,y) point is inside the given polygon
int pnpoly(int npol, const double *xp, const double *yp, double x, double y) {
    int i, j, c = 0;
    for (i = 0, j = npol-1; i < npol; j = i++)
        if ((((yp[i] <= y) && (y < yp[j])) ||
            ((yp[j] <= y) && (y < yp[i]))) &&
            (x < (xp[j] - xp[i]) * (y - yp[i]) / (yp[j] - yp[i]) + xp[i]))
            c = !c;

    return c;
}

int main() {
    int npol = 20;
    double xp[20] = {0.0,1.0,1.0,0.0,0.0,1.0,-0.5,-1.0,-1.0,-2.0,
                     -2.5,-2.0,-1.5,-.5,1.0,1.0,0.0,-0.5,-1.0,-.5};
    double yp[20] = {0.0,0.0,1.0,1.0,2.0,3.0,2.0,3.0,0.0,-.5,
                     -1.0,-1.5,-2.0,-2.0,-1.5,-1.0,-.5,-1.0,-1.0,-.5};
    int i;
    int count = 0;
    for (i = 0; i < 1000000; i++) {
        if (pnpoly(npol, xp, yp, 0.5, 0.5))    count++;
        if (pnpoly(npol, xp, yp, 0.5, 1.5))    count++;
        if (pnpoly(npol, xp, yp, -0.5, 1.5))   count++;
        if (pnpoly(npol, xp, yp, 0.75, 2.25))  count++;
        if (pnpoly(npol, xp, yp, 0.0, 2.01))   count++;
        if (pnpoly(npol, xp, yp, -0.5, 2.5))   count++;
        if (pnpoly(npol, xp, yp, -1.0, -0.5))  count++;
        if (pnpoly(npol, xp, yp, -1.5, 0.5))   count++;
        if (pnpoly(npol, xp, yp, -2.25, -1.0)) count++;
        if (pnpoly(npol, xp, yp, 0.5, -0.25))  count++;
        if (pnpoly(npol, xp, yp, 0.5, -1.25))  count++;
        if (pnpoly(npol, xp, yp, -0.5, -2.5))  count++;
    }
    printf("count %d \n", count);

    return 0;
}



Code compiled with (with gcc and llvm-gcc):
llvm-gcc -Wall -O3 -s -fomit-frame-pointer -msse3 -march=native -ffast-math

Using -ftree-vectorizer-verbose=5
Says GCC: note: vectorized 0 loops in function.

Timings, best of 3, seconds:
  GCC:      0.87
  LLVM-GCC: 1.24

(Feel free to increase the loop count if you have a faster PC.)

Compilers:
  LLVM 2.5, V.4.2.1 (Based on Apple Inc. build 5636) (LLVM build)
  gcc version 4.3.3-dw2-tdm-1 (GCC)

Windows Vista 32 bit on Celeron 2.13 MHz.

I have compiled the code with the daily build of LDC too (a D version) that
uses the latest LLVM 2.6, with similar results.


-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list