Skip to content

Instantly share code, notes, and snippets.

@aaronmccall
Last active June 4, 2016 02:44
Show Gist options
  • Save aaronmccall/10315989e3da2c182ece to your computer and use it in GitHub Desktop.
Save aaronmccall/10315989e3da2c182ece to your computer and use it in GitHub Desktop.
An expirement

This was an experiment to come up with an efficient cache key generator for lat/lng origin/destination pairs.

It seemed to work pretty well, generating nearly a million keys in 66ms.

var each = require('lodash.foreach');
// Creates a non-colliding key for any lat/long pair
function latLongKey(obj) {
// Ensure all values are positive by
// shifting negative latitude to be between 90 and 180
var lat = obj.latitude < 0 ? 180 + obj.latitude : obj.latitude;
// and shifting negative longitude to be between 180 and 360
var lon = obj.longitude < 0 ? 360 + obj.longitude : obj.longitude;
// Shift all significant digits far enough to the left
// to create an integer with the leftmost 7 digits being
// latitude and the rightmost 8 digits being longitude
// then encode to base 36
return ((lat * 1e13) + (lon * 1e5)).toString(36);
}
// Returns the same key for the same two points
// regardless of the order in which they are presented
function pairKey(from, to) {
return (from < to ? from : to) + '-' + (from < to ? to : from)
}
var data = [{
"origin": {
"latitude": 38.374224,
"longitude": -83.430973
},
"destinations": [{
"latitude": 40.964257,
"longitude": -83.023035,
"drivingDistance": 214.23057799875698
}, {
"latitude": 35.955746,
"longitude": -83.927162,
"drivingDistance": 225.56681168427596
}, {
"latitude": 39.76723,
"longitude": -81.94095,
"drivingDistance": 168.12243629583594
}, {
"latitude": 36.96934,
"longitude": -82.55917,
"drivingDistance": 155.88999378495961
}, {
"latitude": 38.34858,
"longitude": -81.62976,
"drivingDistance": 129.71224362958358
}, {
"latitude": 40.54502,
"longitude": -81.2726,
"drivingDistance": 246.11870727159726
}, {
"latitude": 39.358065,
"longitude": -84.247587,
"drivingDistance": 131.9477936606588
}, {
"latitude": 40.51497,
"longitude": -83.90685,
"drivingDistance": 204.0124300807955
}, {
"latitude": 39.768403,
"longitude": -86.158068,
"drivingDistance": 220.53635798632692
}, {
"latitude": 40.09296,
"longitude": -82.652083,
"drivingDistance": 162.6016159105034
}]
}, {
"origin": {
"latitude": 36.056243,
"longitude": -90.479117
},
"destinations": [{
"latitude": 35.13954,
"longitude": -90.05185,
"drivingDistance": 90.10130515848354
}]
}, {
"origin": {
"latitude": 35.08762,
"longitude": -92.49954
},
"destinations": [{
"latitude": 34.53927,
"longitude": -92.63227,
"drivingDistance": 53.07458048477316
}]
}, {
"origin": {
"latitude": 40.54502,
"longitude": -81.2726
},
"destinations": [{
"latitude": 39.673158,
"longitude": -79.85358,
"drivingDistance": 147.40646364201368
}, {
"latitude": 40.964257,
"longitude": -83.023035,
"drivingDistance": 115.76320696084525
}, {
"latitude": 40.28934,
"longitude": -80.1127,
"drivingDistance": 92.9577377252952
}, {
"latitude": 39.76723,
"longitude": -81.94095,
"drivingDistance": 93.92355500310751
}, {
"latitude": 40.09296,
"longitude": -82.652083,
"drivingDistance": 101.21379738968304
}]
}, {
"origin": {
"latitude": 43.330083,
"longitude": -96.713613
},
"destinations": [{
"latitude": 43.651359,
"longitude": -97.778559,
"drivingDistance": 77.93536357986326
}, {
"latitude": 43.330083,
"longitude": -96.713613,
"drivingDistance": 0
}]
}, {
"origin": {
"latitude": 39.295402,
"longitude": -84.523787
},
"destinations": [{
"latitude": 39.358065,
"longitude": -84.247587,
"drivingDistance": 19.162212554381604
}, {
"latitude": 38.374224,
"longitude": -83.430973,
"drivingDistance": 130.633312616532
}, {
"latitude": 40.51497,
"longitude": -83.90685,
"drivingDistance": 115.29770043505283
}, {
"latitude": 39.768403,
"longitude": -86.158068,
"drivingDistance": 108.78371659415785
}]
}, {
"origin": {
"latitude": 33.38412,
"longitude": -84.31229
},
"destinations": [{
"latitude": 33.27346,
"longitude": -84.30795,
"drivingDistance": 9.28713486637663
}, {
"latitude": 33.901736,
"longitude": -84.593568,
"drivingDistance": 50.50466128029832
}]
}, {
"origin": {
"latitude": 33.472257,
"longitude": -94.078354
},
"destinations": [{
"latitude": 34.53927,
"longitude": -92.63227,
"drivingDistance": 116.52765692977005
}]
}, {
"origin": {
"latitude": 43.330083,
"longitude": -96.713613
},
"destinations": [{
"latitude": 43.651359,
"longitude": -97.778559,
"drivingDistance": 77.93536357986326
}, {
"latitude": 42.04037,
"longitude": -97.43677,
"drivingDistance": 124.83281541330018
}]
}, {
"origin": {
"latitude": 38.83547,
"longitude": -77.30921
},
"destinations": [{
"latitude": 39.673158,
"longitude": -79.85358,
"drivingDistance": 205.6575512740833
}, {
"latitude": 40.02405,
"longitude": -76.20054,
"drivingDistance": 140.78620261031696
}, {
"latitude": 38.63414,
"longitude": -77.29762,
"drivingDistance": 17.326289620882537
}, {
"latitude": 39.56089,
"longitude": -76.28315,
"drivingDistance": 91.07520198881292
}, {
"latitude": 40.27989,
"longitude": -77.92091,
"drivingDistance": 139.01988812927283
}, {
"latitude": 37.841373,
"longitude": -77.44934,
"drivingDistance": 77.41640770665009
}, {
"latitude": 39.4863773,
"longitude": -75.0259637,
"drivingDistance": 163.7489123679304
}, {
"latitude": 40.030929,
"longitude": -77.5338,
"drivingDistance": 111.88937228091983
}]
}, {
"origin": {
"latitude": 28.427698,
"longitude": -81.342174
},
"destinations": [{
"latitude": 28.39999,
"longitude": -80.6169,
"drivingDistance": 47.424487259167186
}, {
"latitude": 28.39999,
"longitude": -80.6169,
"drivingDistance": 47.69670602858918
}, {
"latitude": 28.39999,
"longitude": -80.6169,
"drivingDistance": 47.424487259167186
}, {
"latitude": 28.39999,
"longitude": -80.6169,
"drivingDistance": 47.69670602858918
}, {
"latitude": 28.39999,
"longitude": -80.6169,
"drivingDistance": 47.424487259167186
}, {
"latitude": 28.41488,
"longitude": -81.46299,
"drivingDistance": 11.118085767557488
}, {
"latitude": 26.93626,
"longitude": -82.05219,
"drivingDistance": 131.86513362336854
}, {
"latitude": 27.47555,
"longitude": -82.38063,
"drivingDistance": 120.57178371659415
}, {
"latitude": 28.08061,
"longitude": -81.97842,
"drivingDistance": 51.39216904909882
}, {
"latitude": 27.88366,
"longitude": -82.81574,
"drivingDistance": 107.54257302672468
}, {
"latitude": 29.16748,
"longitude": -82.09822,
"drivingDistance": 86.59540087010565
}, {
"latitude": 28.427698,
"longitude": -81.342174,
"drivingDistance": 0
}]
}, {
"origin": {
"latitude": 38.04875,
"longitude": -84.50102
},
"destinations": [{
"latitude": 39.358065,
"longitude": -84.247587,
"drivingDistance": 107.21068986948416
}, {
"latitude": 38.374224,
"longitude": -83.430973,
"drivingDistance": 77.45121193287757
}]
}, {
"origin": {
"latitude": 39.375064,
"longitude": -86.85153
},
"destinations": [{
"latitude": 39.768403,
"longitude": -86.158068,
"drivingDistance": 56.88191423244251
}]
}, {
"origin": {
"latitude": 40.10914,
"longitude": -88.2304
},
"destinations": [{
"latitude": 41.15358,
"longitude": -87.87518,
"drivingDistance": 79.43318831572405
}]
}, {
"origin": {
"latitude": 41.26067,
"longitude": -95.94112
},
"destinations": [{
"latitude": 40.74594,
"longitude": -96.62488,
"drivingDistance": 59.15475450590429
}, {
"latitude": 42.04037,
"longitude": -97.43677,
"drivingDistance": 120.38719701678062
}, {
"latitude": 41.205265,
"longitude": -96.037029,
"drivingDistance": 9.091982597886886
}]
}, {
"origin": {
"latitude": 42.063359,
"longitude": -88.119373
},
"destinations": [{
"latitude": 41.15358,
"longitude": -87.87518,
"drivingDistance": 82.00062150403977
}]
}, {
"origin": {
"latitude": 41.59155,
"longitude": -93.62148
},
"destinations": [{
"latitude": 40.196426,
"longitude": -94.051143,
"drivingDistance": 111.8091982597887
}]
}, {
"origin": {
"latitude": 43.045248,
"longitude": -89.379446
},
"destinations": [{
"latitude": 44.083072,
"longitude": -88.529103,
"drivingDistance": 97.07644499689248
}]
}, {
"origin": {
"latitude": 39.76409,
"longitude": -86.15547
},
"destinations": [{
"latitude": 39.768403,
"longitude": -86.158068,
"drivingDistance": 0.4636420136730889
}]
}, {
"origin": {
"latitude": 40.43883,
"longitude": -79.99094
},
"destinations": [{
"latitude": 39.673158,
"longitude": -79.85358,
"drivingDistance": 72.97576134244873
}, {
"latitude": 40.28934,
"longitude": -80.1127,
"drivingDistance": 13.233685518955873
}, {
"latitude": 40.54502,
"longitude": -81.2726,
"drivingDistance": 89.14170292106898
}]
}, {
"origin": {
"latitude": 41.11437,
"longitude": -85.12328
},
"destinations": [{
"latitude": 41.07823,
"longitude": -85.14562,
"drivingDistance": 3.2945929148539466
}, {
"latitude": 40.51497,
"longitude": -83.90685,
"drivingDistance": 91.32069608452456
}]
}, {
"origin": {
"latitude": 36.15248,
"longitude": -95.99478
},
"destinations": [{
"latitude": 36.050487,
"longitude": -95.95772,
"drivingDistance": 10.354878806712245
}]
}, {
"origin": {
"latitude": 37.6824,
"longitude": -97.33162
},
"destinations": [{
"latitude": 37.73463,
"longitude": -97.24464,
"drivingDistance": 10.998135487880672
}]
}, {
"origin": {
"latitude": 29.7516,
"longitude": -95.36151
},
"destinations": [{
"latitude": 29.90493,
"longitude": -95.68556,
"drivingDistance": 27.072715972653825
}]
}, {
"origin": {
"latitude": 32.464939,
"longitude": -93.674934
},
"destinations": [{
"latitude": 33.472257,
"longitude": -94.078354,
"drivingDistance": 84.92293349906774
}]
}, {
"origin": {
"latitude": 32.75731,
"longitude": -97.329139
},
"destinations": [{
"latitude": 32.89905,
"longitude": -97.23869,
"drivingDistance": 14.201988812927283
}, {
"latitude": 33.04898,
"longitude": -96.61184,
"drivingDistance": 56.47607209446862
}]
}, {
"origin": {
"latitude": 44.083072,
"longitude": -88.529103
},
"destinations": [{
"latitude": 42.7204,
"longitude": -83.34021,
"drivingDistance": 481.38346799254197
}, {
"latitude": 41.15358,
"longitude": -87.87518,
"drivingDistance": 238.01305158483532
}, {
"latitude": 41.07823,
"longitude": -85.14562,
"drivingDistance": 343.54630205096333
}, {
"latitude": 45.12962,
"longitude": -92.68265,
"drivingDistance": 264.56183965195777
}]
}, {
"origin": {
"latitude": 35.13954,
"longitude": -90.05185
},
"destinations": [{
"latitude": 35.13954,
"longitude": -90.05185,
"drivingDistance": 0
}]
}, {
"origin": {
"latitude": 34.75584,
"longitude": -92.2656
},
"destinations": [{
"latitude": 35.08762,
"longitude": -92.49954,
"drivingDistance": 32.46985705407085
}, {
"latitude": 34.53927,
"longitude": -92.63227,
"drivingDistance": 28.10441267868241
}]
}, {
"origin": {
"latitude": 34.25757,
"longitude": -88.69911
},
"destinations": [{
"latitude": 35.13954,
"longitude": -90.05185,
"drivingDistance": 109.78682411435673
}]
}, {
"origin": {
"latitude": 41.50238,
"longitude": -81.656447
},
"destinations": [{
"latitude": 40.964257,
"longitude": -83.023035,
"drivingDistance": 96.54940957116222
}, {
"latitude": 40.54502,
"longitude": -81.2726,
"drivingDistance": 85.13921690490989
}]
}, {
"origin": {
"latitude": 42.32469,
"longitude": -83.05028
},
"destinations": [{
"latitude": 40.964257,
"longitude": -83.023035,
"drivingDistance": 124.26289620882535
}, {
"latitude": 42.7204,
"longitude": -83.34021,
"drivingDistance": 39.43753884400248
}]
}, {
"origin": {
"latitude": 39.09737,
"longitude": -84.50518
},
"destinations": [{
"latitude": 39.358065,
"longitude": -84.247587,
"drivingDistance": 25.563704164077066
}, {
"latitude": 38.374224,
"longitude": -83.430973,
"drivingDistance": 108.11932877563704
}, {
"latitude": 39.768403,
"longitude": -86.158068,
"drivingDistance": 112.94903666873836
}]
}, {
"origin": {
"latitude": 36.85392,
"longitude": -76.28545
},
"destinations": [{
"latitude": 37.841373,
"longitude": -77.44934,
"drivingDistance": 110.06152889993785
}]
}, {
"origin": {
"latitude": 36.06053,
"longitude": -79.82644
},
"destinations": [{
"latitude": 35.747176,
"longitude": -81.378187,
"drivingDistance": 98.60907395898074
}]
}, {
"origin": {
"latitude": 35.955746,
"longitude": -83.927162
},
"destinations": [{
"latitude": 35.955746,
"longitude": -83.927162,
"drivingDistance": 0
}]
}, {
"origin": {
"latitude": 34.85268,
"longitude": -82.39048
},
"destinations": [{
"latitude": 35.747176,
"longitude": -81.378187,
"drivingDistance": 115.88502175264139
}]
}, {
"origin": {
"latitude": 33.757796,
"longitude": -84.401405
},
"destinations": [{
"latitude": 33.27346,
"longitude": -84.30795,
"drivingDistance": 36.88502175264139
}, {
"latitude": 33.901736,
"longitude": -84.593568,
"drivingDistance": 22.57675574891237
}]
}, {
"origin": {
"latitude": 35.46428,
"longitude": -97.51498
},
"destinations": [{
"latitude": 36.050487,
"longitude": -95.95772,
"drivingDistance": 107.82349285270354
}]
}, {
"origin": {
"latitude": 39.096856,
"longitude": -94.581072
},
"destinations": [{
"latitude": 40.196426,
"longitude": -94.051143,
"drivingDistance": 85.83405842137974
}]
}, {
"origin": {
"latitude": 37.97317,
"longitude": -87.56794
},
"destinations": [{
"latitude": 37.087,
"longitude": -88.59425,
"drivingDistance": 128.20261031696705
}, {
"latitude": 37.339939,
"longitude": -86.971686,
"drivingDistance": 81.39154754505904
}]
}, {
"origin": {
"latitude": 40.69116,
"longitude": -89.59316
},
"destinations": [{
"latitude": 41.15358,
"longitude": -87.87518,
"drivingDistance": 122.55003107520199
}]
}, {
"origin": {
"latitude": 38.192761,
"longitude": -85.74081
},
"destinations": [{
"latitude": 37.339939,
"longitude": -86.971686,
"drivingDistance": 116.04847731510256
}]
}, {
"origin": {
"latitude": 38.62643,
"longitude": -90.20261
},
"destinations": [{
"latitude": 38.74762,
"longitude": -90.51083,
"drivingDistance": 25.570540708514606
}]
}, {
"origin": {
"latitude": 40.00869,
"longitude": -83.025907
},
"destinations": [{
"latitude": 40.964257,
"longitude": -83.023035,
"drivingDistance": 76.41765071472965
}, {
"latitude": 39.76723,
"longitude": -81.94095,
"drivingDistance": 77.72778123057799
}, {
"latitude": 40.54502,
"longitude": -81.2726,
"drivingDistance": 135.67992541951523
}, {
"latitude": 39.358065,
"longitude": -84.247587,
"drivingDistance": 86.11995027967683
}, {
"latitude": 40.51497,
"longitude": -83.90685,
"drivingDistance": 71.4636420136731
}, {
"latitude": 40.09296,
"longitude": -82.652083,
"drivingDistance": 29.70665009322561
}]
}, {
"origin": {
"latitude": 40.810161,
"longitude": -77.854931
},
"destinations": [{
"latitude": 41.046976,
"longitude": -77.832697,
"drivingDistance": 26.9397141081417
}, {
"latitude": 40.27989,
"longitude": -77.92091,
"drivingDistance": 50.97078931013051
}, {
"latitude": 40.030929,
"longitude": -77.5338,
"drivingDistance": 85.89683032939715
}]
}, {
"origin": {
"latitude": 40.33779,
"longitude": -75.925844
},
"destinations": [{
"latitude": 40.02405,
"longitude": -76.20054,
"drivingDistance": 37.34617775015538
}, {
"latitude": 39.56089,
"longitude": -76.28315,
"drivingDistance": 72.74518334369174
}, {
"latitude": 39.4863773,
"longitude": -75.0259637,
"drivingDistance": 102.87880671224363
}, {
"latitude": 40.030929,
"longitude": -77.5338,
"drivingDistance": 107.1385954008701
}]
}, {
"origin": {
"latitude": 35.050667,
"longitude": -85.299746
},
"destinations": [{
"latitude": 35.955746,
"longitude": -83.927162,
"drivingDistance": 112.49347420758235
}, {
"latitude": 33.901736,
"longitude": -84.593568,
"drivingDistance": 106.48042262274704
}]
}, {
"origin": {
"latitude": 27.9428,
"longitude": -82.45172
},
"destinations": [{
"latitude": 28.41488,
"longitude": -81.46299,
"drivingDistance": 73.54381603480422
}, {
"latitude": 26.93626,
"longitude": -82.05219,
"drivingDistance": 102.5363579863269
}, {
"latitude": 27.47555,
"longitude": -82.38063,
"drivingDistance": 50.28527035425731
}, {
"latitude": 28.08061,
"longitude": -81.97842,
"drivingDistance": 34.03293971410814
}, {
"latitude": 27.88366,
"longitude": -82.81574,
"drivingDistance": 24.91236793039155
}, {
"latitude": 29.16748,
"longitude": -82.09822,
"drivingDistance": 99.0863890615289
}, {
"latitude": 28.427698,
"longitude": -81.342174,
"drivingDistance": 84.51957737725294
}]
}, {
"origin": {
"latitude": 30.32572,
"longitude": -81.6437
},
"destinations": [{
"latitude": 29.16748,
"longitude": -82.09822,
"drivingDistance": 106.89807333747669
}]
}, {
"origin": {
"latitude": 35.22538,
"longitude": -80.83987
},
"destinations": [{
"latitude": 35.747176,
"longitude": -81.378187,
"drivingDistance": 59.998135487880674
}]
}, {
"origin": {
"latitude": 38.35507,
"longitude": -81.64147
},
"destinations": [{
"latitude": 39.76723,
"longitude": -81.94095,
"drivingDistance": 136.5680546923555
}, {
"latitude": 38.34858,
"longitude": -81.62976,
"drivingDistance": 1.0080795525170914
}, {
"latitude": 38.374224,
"longitude": -83.430973,
"drivingDistance": 128.17961466749534
}]
}, {
"origin": {
"latitude": 33.04898,
"longitude": -96.61184
},
"destinations": [{
"latitude": 32.89905,
"longitude": -97.23869,
"drivingDistance": 52.52392790553139
}]
}, {
"origin": {
"latitude": 33.901736,
"longitude": -84.593568
},
"destinations": [{
"latitude": 33.27346,
"longitude": -84.30795,
"drivingDistance": 58.87010565568676
}]
}, {
"origin": {
"latitude": 38.540534,
"longitude": -121.551591
},
"destinations": [{
"latitude": 38.59502,
"longitude": -121.42932,
"drivingDistance": 10.486016159105034
}]
}, {
"origin": {
"latitude": 33.7668,
"longitude": -118.18933
},
"destinations": [{
"latitude": 34.26448,
"longitude": -118.76493,
"drivingDistance": 63.812927284027346
}]
}, {
"origin": {
"latitude": 33.53026,
"longitude": -112.26203
},
"destinations": [{
"latitude": 34.58868,
"longitude": -112.33709,
"drivingDistance": 90.99627097576135
}]
}, {
"origin": {
"latitude": 42.92715,
"longitude": -78.39013
},
"destinations": [{
"latitude": 41.046976,
"longitude": -77.832697,
"drivingDistance": 176.05904288377874
}, {
"latitude": 43.024732,
"longitude": -78.752689,
"drivingDistance": 32.77936606587943
}, {
"latitude": 40.27989,
"longitude": -77.92091,
"drivingDistance": 241.11932877563706
}]
}, {
"origin": {
"latitude": 34.0727055,
"longitude": -117.5661018
},
"destinations": [{
"latitude": 34.26448,
"longitude": -118.76493,
"drivingDistance": 80.20758234928527
}]
}, {
"origin": {
"latitude": 45.146769,
"longitude": -95.007377
},
"destinations": [{
"latitude": 43.651359,
"longitude": -97.778559,
"drivingDistance": 213.90366687383468
}, {
"latitude": 45.12962,
"longitude": -92.68265,
"drivingDistance": 149.78744561839653
}, {
"latitude": 43.330083,
"longitude": -96.713613,
"drivingDistance": 177.4058421379739
}]
}, {
"origin": {
"latitude": 40.27989,
"longitude": -77.92091
},
"destinations": [{
"latitude": 39.673158,
"longitude": -79.85358,
"drivingDistance": 150.1988812927284
}, {
"latitude": 41.046976,
"longitude": -77.832697,
"drivingDistance": 81.87569919204475
}, {
"latitude": 40.02405,
"longitude": -76.20054,
"drivingDistance": 119.48353014294592
}, {
"latitude": 40.28934,
"longitude": -80.1127,
"drivingDistance": 163.86264760720942
}, {
"latitude": 38.63414,
"longitude": -77.29762,
"drivingDistance": 153.2144188937228
}, {
"latitude": 39.56089,
"longitude": -76.28315,
"drivingDistance": 143.71783716594157
}, {
"latitude": 43.024732,
"longitude": -78.752689,
"drivingDistance": 241.2038533250466
}, {
"latitude": 40.54502,
"longitude": -81.2726,
"drivingDistance": 239.2691112492231
}, {
"latitude": 40.27989,
"longitude": -77.92091,
"drivingDistance": 0
}, {
"latitude": 37.841373,
"longitude": -77.44934,
"drivingDistance": 212.92044748290863
}, {
"latitude": 39.4863773,
"longitude": -75.0259637,
"drivingDistance": 220.90739589807333
}, {
"latitude": 40.030929,
"longitude": -77.5338,
"drivingDistance": 38.880049720323186
}]
}, {
"origin": {
"latitude": 37.95935,
"longitude": -121.9466
},
"destinations": [{
"latitude": 38.59502,
"longitude": -121.42932,
"drivingDistance": 78.23368551895588
}]
}, {
"origin": {
"latitude": 33.650171,
"longitude": -117.747504
},
"destinations": [{
"latitude": 34.26448,
"longitude": -118.76493,
"drivingDistance": 84.84835301429459
}]
}, {
"origin": {
"latitude": 39.21854,
"longitude": -78.19364
},
"destinations": [{
"latitude": 39.673158,
"longitude": -79.85358,
"drivingDistance": 126.08576755748913
}, {
"latitude": 38.63414,
"longitude": -77.29762,
"drivingDistance": 83.905531385954
}, {
"latitude": 40.27989,
"longitude": -77.92091,
"drivingDistance": 90.07830950901182
}, {
"latitude": 40.030929,
"longitude": -77.5338,
"drivingDistance": 73.85021752641393
}]
}, {
"origin": {
"latitude": 36.154335,
"longitude": -86.789548
},
"destinations": [{
"latitude": 37.339939,
"longitude": -86.971686,
"drivingDistance": 116.5288999378496
}]
}, {
"origin": {
"latitude": 36.124123,
"longitude": -80.253563
},
"destinations": [{
"latitude": 35.747176,
"longitude": -81.378187,
"drivingDistance": 74.77439403356122
}]
}, {
"origin": {
"latitude": 29.98558,
"longitude": -90.24315
},
"destinations": [{
"latitude": 30.53485,
"longitude": -90.987899,
"drivingDistance": 79.35922933499067
}]
}, {
"origin": {
"latitude": 40.111095,
"longitude": -85.653606
},
"destinations": [{
"latitude": 41.07823,
"longitude": -85.14562,
"drivingDistance": 80.60285891858297
}, {
"latitude": 39.358065,
"longitude": -84.247587,
"drivingDistance": 136.2747047855811
}, {
"latitude": 40.51497,
"longitude": -83.90685,
"drivingDistance": 116.86264760720945
}, {
"latitude": 39.768403,
"longitude": -86.158068,
"drivingDistance": 45.709757613424486
}]
}, {
"origin": {
"latitude": 34.93359,
"longitude": -95.76748
},
"destinations": [{
"latitude": 36.050487,
"longitude": -95.95772,
"drivingDistance": 87.95338719701678
}]
}, {
"origin": {
"latitude": 33.75907,
"longitude": -96.58159
},
"destinations": [{
"latitude": 32.89905,
"longitude": -97.23869,
"drivingDistance": 88.86761963952766
}, {
"latitude": 33.04898,
"longitude": -96.61184,
"drivingDistance": 54.463642013673095
}]
}, {
"origin": {
"latitude": 28.427698,
"longitude": -81.342174
},
"destinations": [{
"latitude": 28.39999,
"longitude": -80.6169,
"drivingDistance": 47.424487259167186
}, {
"latitude": 28.39999,
"longitude": -80.6169,
"drivingDistance": 47.69670602858918
}, {
"latitude": 28.39999,
"longitude": -80.6169,
"drivingDistance": 47.424487259167186
}, {
"latitude": 28.39999,
"longitude": -80.6169,
"drivingDistance": 47.69670602858918
}, {
"latitude": 28.39999,
"longitude": -80.6169,
"drivingDistance": 47.424487259167186
}, {
"latitude": 28.41488,
"longitude": -81.46299,
"drivingDistance": 11.118085767557488
}, {
"latitude": 26.93626,
"longitude": -82.05219,
"drivingDistance": 131.86513362336854
}, {
"latitude": 27.47555,
"longitude": -82.38063,
"drivingDistance": 120.57178371659415
}, {
"latitude": 28.08061,
"longitude": -81.97842,
"drivingDistance": 51.39216904909882
}, {
"latitude": 27.88366,
"longitude": -82.81574,
"drivingDistance": 107.54257302672468
}, {
"latitude": 29.16748,
"longitude": -82.09822,
"drivingDistance": 86.59540087010565
}]
}, {
"origin": {
"latitude": 39.673158,
"longitude": -79.85358
},
"destinations": [{
"latitude": 40.28934,
"longitude": -80.1127,
"drivingDistance": 70.4108141702921
}, {
"latitude": 40.54502,
"longitude": -81.2726,
"drivingDistance": 147.40646364201368
}]
}, {
"origin": {
"latitude": 40.02405,
"longitude": -76.20054
},
"destinations": [{
"latitude": 39.56089,
"longitude": -76.28315,
"drivingDistance": 46.12492231199503
}, {
"latitude": 40.27989,
"longitude": -77.92091,
"drivingDistance": 119.48353014294592
}, {
"latitude": 39.4863773,
"longitude": -75.0259637,
"drivingDistance": 82.37228091982598
}, {
"latitude": 40.030929,
"longitude": -77.5338,
"drivingDistance": 88.27470478558111
}]
}, {
"origin": {
"latitude": 33.27346,
"longitude": -84.30795
},
"destinations": [{
"latitude": 33.901736,
"longitude": -84.593568,
"drivingDistance": 59.17837165941579
}]
}, {
"origin": {
"latitude": 32.89905,
"longitude": -97.23869
},
"destinations": [{
"latitude": 33.04898,
"longitude": -96.61184,
"drivingDistance": 47.424487259167186
}]
}, {
"origin": {
"latitude": 26.93626,
"longitude": -82.05219
},
"destinations": [{
"latitude": 27.47555,
"longitude": -82.38063,
"drivingDistance": 63.36420136730889
}, {
"latitude": 28.08061,
"longitude": -81.97842,
"drivingDistance": 123.97824735860783
}, {
"latitude": 27.88366,
"longitude": -82.81574,
"drivingDistance": 104.96830329397142
}]
}, {
"origin": {
"latitude": 28.08061,
"longitude": -81.97842
},
"destinations": [{
"latitude": 28.39999,
"longitude": -80.6169,
"drivingDistance": 95.23865755127409
}, {
"latitude": 28.39999,
"longitude": -80.6169,
"drivingDistance": 95.46488502175265
}, {
"latitude": 28.39999,
"longitude": -80.6169,
"drivingDistance": 95.23865755127409
}, {
"latitude": 28.39999,
"longitude": -80.6169,
"drivingDistance": 95.46488502175265
}, {
"latitude": 28.39999,
"longitude": -80.6169,
"drivingDistance": 95.23865755127409
}, {
"latitude": 28.41488,
"longitude": -81.46299,
"drivingDistance": 41.12740832815414
}, {
"latitude": 26.93626,
"longitude": -82.05219,
"drivingDistance": 123.97824735860783
}, {
"latitude": 27.47555,
"longitude": -82.38063,
"drivingDistance": 70.4897451833437
}, {
"latitude": 27.88366,
"longitude": -82.81574,
"drivingDistance": 56.37041640770665
}, {
"latitude": 29.16748,
"longitude": -82.09822,
"drivingDistance": 93.82660037290243
}, {
"latitude": 28.427698,
"longitude": -81.342174,
"drivingDistance": 52.18458669981355
}]
}, {
"origin": {
"latitude": 27.47555,
"longitude": -82.38063
},
"destinations": [{
"latitude": 28.41488,
"longitude": -81.46299,
"drivingDistance": 109.59602237414543
}, {
"latitude": 26.93626,
"longitude": -82.05219,
"drivingDistance": 63.36420136730889
}, {
"latitude": 28.08061,
"longitude": -81.97842,
"drivingDistance": 70.4897451833437
}, {
"latitude": 27.88366,
"longitude": -82.81574,
"drivingDistance": 53.24425108763207
}, {
"latitude": 28.427698,
"longitude": -81.342174,
"drivingDistance": 120.57178371659415
}]
}, {
"origin": {
"latitude": 27.88366,
"longitude": -82.81574
},
"destinations": [{
"latitude": 28.41488,
"longitude": -81.46299,
"drivingDistance": 96.56681168427595
}, {
"latitude": 26.93626,
"longitude": -82.05219,
"drivingDistance": 104.96830329397142
}, {
"latitude": 27.47555,
"longitude": -82.38063,
"drivingDistance": 53.24425108763207
}, {
"latitude": 28.08061,
"longitude": -81.97842,
"drivingDistance": 56.37041640770665
}, {
"latitude": 29.16748,
"longitude": -82.09822,
"drivingDistance": 121.75015537600994
}, {
"latitude": 28.427698,
"longitude": -81.342174,
"drivingDistance": 106.46612802983219
}]
}, {
"origin": {
"latitude": 29.16748,
"longitude": -82.09822
},
"destinations": [{
"latitude": 28.41488,
"longitude": -81.46299,
"drivingDistance": 84.54070851460536
}, {
"latitude": 28.08061,
"longitude": -81.97842,
"drivingDistance": 94.09571162212555
}, {
"latitude": 27.88366,
"longitude": -82.81574,
"drivingDistance": 121.10627719080175
}, {
"latitude": 28.427698,
"longitude": -81.342174,
"drivingDistance": 86.59540087010565
}]
}, {
"origin": {
"latitude": 40.74594,
"longitude": -96.62488
},
"destinations": [{
"latitude": 40.90205,
"longitude": -98.327,
"drivingDistance": 97.28962088253573
}, {
"latitude": 42.04037,
"longitude": -97.43677,
"drivingDistance": 131.5183343691734
}, {
"latitude": 41.205265,
"longitude": -96.037029,
"drivingDistance": 51.08576755748913
}]
}, {
"origin": {
"latitude": 38.74762,
"longitude": -90.51083
},
"destinations": [{
"latitude": 39.92837,
"longitude": -91.41094,
"drivingDistance": 118.12430080795527
}]
}, {
"origin": {
"latitude": 41.07823,
"longitude": -85.14562
},
"destinations": [{
"latitude": 40.51497,
"longitude": -83.90685,
"drivingDistance": 90.3039154754506
}]
}, {
"origin": {
"latitude": 38.34858,
"longitude": -81.62976
},
"destinations": [{
"latitude": 39.76723,
"longitude": -81.94095,
"drivingDistance": 136.9794903666874
}, {
"latitude": 38.374224,
"longitude": -83.430973,
"drivingDistance": 129.71224362958358
}]
}, {
"origin": {
"latitude": 39.66189,
"longitude": -105.1875
},
"destinations": [{
"latitude": 39.71216,
"longitude": -105.09484,
"drivingDistance": 10.939714108141704
}]
}, {
"origin": {
"latitude": 28.41488,
"longitude": -81.46299
},
"destinations": [{
"latitude": 28.39999,
"longitude": -80.6169,
"drivingDistance": 54.172156619018025
}, {
"latitude": 28.39999,
"longitude": -80.6169,
"drivingDistance": 54.443132380360474
}, {
"latitude": 28.39999,
"longitude": -80.6169,
"drivingDistance": 54.172156619018025
}, {
"latitude": 28.39999,
"longitude": -80.6169,
"drivingDistance": 54.443132380360474
}, {
"latitude": 28.39999,
"longitude": -80.6169,
"drivingDistance": 54.172156619018025
}, {
"latitude": 26.93626,
"longitude": -82.05219,
"drivingDistance": 121.20509633312616
}, {
"latitude": 27.47555,
"longitude": -82.38063,
"drivingDistance": 110.46550652579242
}, {
"latitude": 28.08061,
"longitude": -81.97842,
"drivingDistance": 41.20882535736483
}, {
"latitude": 27.88366,
"longitude": -82.81574,
"drivingDistance": 96.20136730888751
}, {
"latitude": 29.16748,
"longitude": -82.09822,
"drivingDistance": 84.54070851460536
}, {
"latitude": 28.427698,
"longitude": -81.342174,
"drivingDistance": 11.118085767557488
}]
}];
var start = performance.now();
var i = 100;
var result = {};
var locations = 0;
while (i--) {
each(data, function (set) {
var origin = latLongKey(set.origin);
locations++;
locations += set.destinations.length;
each(set.destinations, function (dest) {
result[pairKey(origin, latLongKey(dest))] = dest.drivingDistance;
});
});
}
var end = performance.now();
console.log("result: %o, locations: %d, uniques: %d, size: %d, elapsed: %s", result, locations, Object.keys(result).length, JSON.stringify(result).length, end - start);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment