Skip to content

Commit

Permalink
Convert bench.js to Typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisCarriere committed Feb 21, 2018
1 parent a626179 commit ebaf489
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 36 deletions.
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ dist

// Typescript compiled files
*.d.ts
index.js
test.js
index.mjs
index.min.js
*.js

# Runtime data
pids
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 2018-02-21 - 0.9.1

- Revert `nodeId` to `number` type.
- Convert `bench.js` to Typescript

## 2018-02-20 - 0.9.0

Expand Down
31 changes: 0 additions & 31 deletions bench.js

This file was deleted.

31 changes: 31 additions & 0 deletions bench.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import Benchmark from "benchmark";
import { FormOfWay } from "sharedstreets-types";
import * as sharedstreets from "./";

// Fixtures
const message = "Intersection 110.000000 45.000000";
const coord = [110, 45];
const geom = [[110, 45], [115, 50], [120, 55]];
const locationReferences = [
sharedstreets.locationReference([-74.00482177734375, 40.741641998291016], {outboundBearing: 208, distanceToNextRef: 9279}),
sharedstreets.locationReference([-74.005126953125, 40.74085235595703], {inboundBearing: 188}),
];
const formOfWay = FormOfWay.MultipleCarriageway;

sharedstreets.referenceId(locationReferences, formOfWay);
/**
* Benchmark Results
*
* generateHash x 475,542 ops/sec ±4.91% (71 runs sampled)
* intersectionId x 177,663 ops/sec ±17.20% (62 runs sampled)
* geometryId x 90,787 ops/sec ±15.06% (62 runs sampled)
* referenceId x 76,479 ops/sec ±5.55% (74 runs sampled)
*/
const suite = new Benchmark.Suite("sharedstreets");
suite
.add("generateHash", () => sharedstreets.generateHash(message))
.add("intersectionId", () => sharedstreets.intersectionId(coord))
.add("geometryId", () => sharedstreets.geometryId(geom))
.add("referenceId", () => sharedstreets.referenceId(locationReferences, formOfWay))
.on("cycle", (e: any) => { process.stdout.write(String(e.target) + "\n"); })
.run();
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"test": "tap test.js",
"posttest": "tslint index.ts --project tsconfig.json",
"docs": "tsc && documentation readme index.js --section=API",
"benchmark": "benchmark bench.js"
"bench": "tsc && node bench.js"
},
"repository": {
"type": "git",
Expand All @@ -35,6 +35,7 @@
},
"homepage": "https://github.com/sharedstreets/sharedstreets.js#readme",
"devDependencies": {
"@types/benchmark": "*",
"@types/glob": "*",
"@types/node": "*",
"@types/tape": "*",
Expand Down
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@
dependencies:
"@turf/helpers" "^5.1.5"

"@types/benchmark@*":
version "1.0.31"
resolved "https://registry.yarnpkg.com/@types/benchmark/-/benchmark-1.0.31.tgz#2dd3514e93396f362ba5551a7c9ff0da405c1d38"

"@types/events@*":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@types/events/-/events-1.1.0.tgz#93b1be91f63c184450385272c47b6496fd028e02"
Expand Down

0 comments on commit ebaf489

Please sign in to comment.