Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timing tests #5

Closed
dpmcmlxxvi opened this issue May 25, 2019 · 4 comments
Closed

Add timing tests #5

dpmcmlxxvi opened this issue May 25, 2019 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@dpmcmlxxvi
Copy link
Owner

Add timing benchmark tests.

@dpmcmlxxvi dpmcmlxxvi added the enhancement New feature or request label May 25, 2019
@dpmcmlxxvi dpmcmlxxvi self-assigned this May 25, 2019
@tordans
Copy link

tordans commented Jan 11, 2022

That would be great.

I am reading the README and I am wondering, which method to pick when more than one would likely solve my problem. A benchmark could help with this decision.


Update:

I was curious about this and googled how to do this in a simple way. Here are my results. Would love to hear if this approach is usable (see "Full code").

Function call Time
de9im.contains(area, lineFullyWithinArea)) 97 ms
de9im.contains(area, lineInAndOutOfArea)) 106 ms
de9im.coveredby(lineFullyWithinArea, area)) 42 ms
de9im.coveredby(lineInAndOutOfArea, area)) 71 ms
de9im.crosses(area, lineFullyWithinArea)) 51 ms
de9im.crosses(area, lineInAndOutOfArea)) 80 ms
de9im.intersects(area, lineFullyWithinArea)) 154 ms
de9im.intersects(area, lineInAndOutOfArea)) 165 ms
de9im.within(lineFullyWithinArea, area)) 45 ms
de9im.within(lineInAndOutOfArea, area)) 71 ms
Full code …
const area = {
  type: "FeatureCollection",
  features: [
    {
      type: "Feature",
      properties: {},
      geometry: {
        type: "Polygon",
        coordinates: [
          [
            [13.587512969970701, 52.3013410761489],
            [13.619956970214844, 52.3013410761489],
            [13.619956970214844, 52.31141727938367],
            [13.587512969970701, 52.31141727938367],
            [13.587512969970701, 52.3013410761489],
          ],
        ],
      },
    },
  ],
}

const lineFullyWithinArea = {
  type: "FeatureCollection",
  features: [
    {
      type: "Feature",
      properties: {},
      geometry: {
        type: "LineString",
        coordinates: [
          [13.594036102294922, 52.30595962063293],
          [13.613433837890625, 52.30784888634275],
        ],
      },
    },
  ],
}

const lineInAndOutOfArea = {
  type: "Feature",
  properties: {},
  geometry: {
    type: "LineString",
    coordinates: [
      [13.5955810546875, 52.30889844356715],
      [13.5955810546875, 52.313935971877584],
    ],
  },
}

import de9im from "de9im"

const test = (consoleLine, callFunction) => {
  const start = Date.now()
  let runs = 10000

  while (runs) {
    callFunction()
    runs--
  }

  console.log("Finished `" + consoleLine + "` " + (Date.now() - start) + " ms.")
}

test("de9im.contains(area, lineFullyWithinArea))", () =>
  de9im.contains(area, lineFullyWithinArea))
test("de9im.contains(area, lineInAndOutOfArea))", () =>
  de9im.contains(area, lineInAndOutOfArea))
test("de9im.coveredby(lineFullyWithinArea, area))", () =>
  de9im.coveredby(lineFullyWithinArea, area))
test("de9im.coveredby(lineInAndOutOfArea, area))", () =>
  de9im.coveredby(lineInAndOutOfArea, area))
test("de9im.crosses(area, lineFullyWithinArea))", () =>
  de9im.crosses(area, lineFullyWithinArea))
test("de9im.crosses(area, lineInAndOutOfArea))", () =>
  de9im.crosses(area, lineInAndOutOfArea))
test("de9im.intersects(area, lineFullyWithinArea))", () =>
  de9im.intersects(area, lineFullyWithinArea))
test("de9im.intersects(area, lineInAndOutOfArea))", () =>
  de9im.intersects(area, lineInAndOutOfArea))
test("de9im.within(lineFullyWithinArea, area))", () =>
  de9im.within(lineFullyWithinArea, area))
test("de9im.within(lineInAndOutOfArea, area))", () =>
  de9im.within(lineInAndOutOfArea, area))

What is interesting is, that in my usecase #44 it looks like it would be faster to first check everything with coveredby (fastest) and only check all non assigned values with intersects (slowest, but the right one for my usecase).

@dpmcmlxxvi
Copy link
Owner Author

I'll look into integrating a bench performance library into the test suite. Generally, using Date.now is discouraged since it can contain timing side-effects that have nothing to do with the code you are measuring. The performance timing API performance.now is preferable.

@dpmcmlxxvi
Copy link
Owner Author

Closed with 52cf6ec.

@dpmcmlxxvi
Copy link
Owner Author

@tordans FYI. Based on the benchmark results it seems like you're better off just running intersects directly if that is the case you are interested in for the line/polygon case. The test geometries used are fairly simple. So, if you are interested in more complex geometries, you can submit an issue for it and I can consider adding it to the bench tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants