Skip to content

Commit

Permalink
I just fucking hate windows man
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr Martian committed Dec 2, 2024
1 parent 4859237 commit c631332
Show file tree
Hide file tree
Showing 12 changed files with 353 additions and 131 deletions.
110 changes: 80 additions & 30 deletions benchmarks/uint64.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
// import { Uint64Cell } from '../src/wasm/uint64';
import { fromLonLat } from '../src/geometry/s2/point';
import { fromS2Point } from '../src/geometry';
// import { fromS2Point } from '../src/geometry/idBig';

// // create two numbers and add them 1_000_000 times
// const startAdd = Bun.nanoseconds();
// for (let i = 0; i < 1_000_000; i++) {
// const id1 = Uint64Cell.fromNumber(0);
// const id2 = Uint64Cell.fromNumber(10_000);
// const _addRes = id1.add(id2);
// const _subRes = id1.sub(id2);
// const _mulRes = id1.mul(id2);
// const _divRes = id1.div(id2);
// const _toLoHiRes1 = id1.toLoHi();
// const _toLoHiRes2 = id2.toLoHi();
// // import { Uint64Cell } from '../src/wasm/uint64';
// import { fromLonLat } from '../src/geometry/s2/point';
// import { fromS2Point } from '../src/geometry';
// // import { fromS2Point } from '../src/geometry/idBig';

// // // create two numbers and add them 1_000_000 times
// // const startAdd = Bun.nanoseconds();
// // for (let i = 0; i < 1_000_000; i++) {
// // const id1 = Uint64Cell.fromNumber(0);
// // const id2 = Uint64Cell.fromNumber(10_000);
// // const _addRes = id1.add(id2);
// // const _subRes = id1.sub(id2);
// // const _mulRes = id1.mul(id2);
// // const _divRes = id1.div(id2);
// // const _toLoHiRes1 = id1.toLoHi();
// // const _toLoHiRes2 = id2.toLoHi();
// // }
// // const endAdd = Bun.nanoseconds();
// // const secondsAdd = (endAdd - startAdd) / 1_000_000_000;
// // console.info('Add time: ', secondsAdd);

// const start = Bun.nanoseconds();
// for (let i = 0; i < 100_000; i++) {
// const lon = getRandomInt(-180, 180);
// const lat = getRandomInt(-90, 90);
// const point = fromLonLat(lon, lat);
// const _cell = fromS2Point(point);
// }
// const endAdd = Bun.nanoseconds();
// const secondsAdd = (endAdd - startAdd) / 1_000_000_000;
// console.info('Add time: ', secondsAdd);

const start = Bun.nanoseconds();
for (let i = 0; i < 100_000; i++) {
const lon = getRandomInt(-180, 180);
const lat = getRandomInt(-90, 90);
const point = fromLonLat(lon, lat);
const _cell = fromS2Point(point);
}
const end = Bun.nanoseconds();
const seconds = (end - start) / 1_000_000_000;
console.info('Point time: ', seconds);
// const end = Bun.nanoseconds();
// const seconds = (end - start) / 1_000_000_000;
// console.info('Point time: ', seconds);

/**
* Generate a random whole number between two given values.
Expand All @@ -45,3 +45,53 @@ function getRandomInt(a: number, b: number): number {
const max = Math.floor(b);
return Math.floor(Math.random() * (max - min + 1)) + min;
}

import Long from 'long';

const SIZE = 1_000_000;

// const x = Long.fromString('2', true);
// console.log('x', x);

const longs: Long[] = [];
const bigInts: bigint[] = [];

const startLongCreation = Bun.nanoseconds();
for (let i = 0; i < SIZE; i++) {
longs.push(Long.fromValue(i, true));
}
const endLongCreation = Bun.nanoseconds();

const startBigIntCreation = Bun.nanoseconds();
for (let i = 0; i < SIZE; i++) {
bigInts.push(BigInt(i));
}
const endBigIntCreation = Bun.nanoseconds();

const secondsLongCreation = (endLongCreation - startLongCreation) / 1_000_000_000;
const secondsBigIntCreation = (endBigIntCreation - startBigIntCreation) / 1_000_000_000;

console.info('Long creation time: ', secondsLongCreation);
console.info('BigInt creation time: ', secondsBigIntCreation);

// lets test multiplying by a random number for every long

const startLongMul = Bun.nanoseconds();
for (let i = 0; i < SIZE; i++) {
const rand = getRandomInt(0, SIZE);
const _mulRes = longs[i].mul(Long.fromValue(rand, true));
}
const endLongMul = Bun.nanoseconds();
const secondsLongMul = (endLongMul - startLongMul) / 1_000_000_000;
console.info('Long mul time: ', secondsLongMul);

// lets test multiplying by a random number for every bigint

const startBigIntMul = Bun.nanoseconds();
for (let i = 0; i < SIZE; i++) {
const rand = getRandomInt(0, SIZE);
const _mulRes = bigInts[i] * BigInt(rand);
}
const endBigIntMul = Bun.nanoseconds();
const secondsBigIntMul = (endBigIntMul - startBigIntMul) / 1_000_000_000;
console.info('BigInt mul time: ', secondsBigIntMul);
Binary file modified bun.lockb
Binary file not shown.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"geotiff": "^2.1.3",
"kdbush": "^4.0.2",
"lmdb": "^3.1.3",
"long": "^5.2.3",
"mitata": "^1.0.10",
"nextafter": "^1.0.0",
"prettier": "^3.3.3",
Expand All @@ -96,7 +97,7 @@
"dependencies": {
"earclip": "^1.1.0",
"open-vector-tile": "^1.3.0",
"s2-tilejson": "^1.6.0",
"s2-tilejson": "^1.7.0",
"s2json-spec": "^1.6.0",
"sharp": "^0.33.5"
}
Expand Down
Loading

0 comments on commit c631332

Please sign in to comment.