|
| 1 | +/* |
| 2 | + * Copyright 2017, 2020-2021 Uber Technologies, Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +#include "algos.h" |
| 17 | +#include "benchmark.h" |
| 18 | +#include "h3api.h" |
| 19 | +#include "polyfill.h" |
| 20 | + |
| 21 | +// Fixtures |
| 22 | +LatLng sfVerts[] = { |
| 23 | + {0.659966917655, -2.1364398519396}, {0.6595011102219, -2.1359434279405}, |
| 24 | + {0.6583348114025, -2.1354884206045}, {0.6581220034068, -2.1382437718946}, |
| 25 | + {0.6594479998527, -2.1384597563896}, {0.6599990002976, -2.1376771158464}}; |
| 26 | +GeoLoop sfGeoLoop; |
| 27 | +GeoPolygon sfGeoPolygon; |
| 28 | + |
| 29 | +LatLng alamedaVerts[] = {{0.6597959342671712, -2.133241848488897}, |
| 30 | + {0.6597959348850178, -2.133241848495878}, |
| 31 | + {0.6598352639563587, -2.1331688423977755}, |
| 32 | + {0.6601346536539207, -2.13270417124178}, |
| 33 | + {0.6601594763880223, -2.1326680320633344}, |
| 34 | + {0.6601512007732382, -2.1326594176574534}, |
| 35 | + {0.6598535076212304, -2.1323049630593562}, |
| 36 | + {0.6596565748646488, -2.132069889917591}, |
| 37 | + {0.6594645035394391, -2.131843148468039}, |
| 38 | + {0.6593438094209757, -2.1316994860539844}, |
| 39 | + {0.6591174422311021, -2.131429776816562}, |
| 40 | + {0.658849344286881, -2.1311111485483867}, |
| 41 | + {0.6588348862079956, -2.1310988536794455}, |
| 42 | + {0.6586273138317915, -2.131668420800747}, |
| 43 | + {0.6583729538174264, -2.132370426573979}, |
| 44 | + {0.6582479206289285, -2.132718691911663}, |
| 45 | + {0.6582322393220743, -2.1327614200082317}, |
| 46 | + {0.6583003647098981, -2.132837478687196}, |
| 47 | + {0.6584457274847966, -2.132827956758973}, |
| 48 | + {0.6585526679060995, -2.1330231566043203}, |
| 49 | + {0.6587379099516777, -2.1331602726234538}, |
| 50 | + {0.6587273684736642, -2.1332676321559063}, |
| 51 | + {0.6584638025857692, -2.133305719954319}, |
| 52 | + {0.6583545950288919, -2.1334323622944993}, |
| 53 | + {0.6584427148370682, -2.1335885223323947}, |
| 54 | + {0.6584715236640714, -2.133649780409862}, |
| 55 | + {0.6584715242505019, -2.133649780481421}, |
| 56 | + {0.658474662092443, -2.1336459234695804}, |
| 57 | + {0.6591666596433436, -2.1348354004882926}, |
| 58 | + {0.6591809355063646, -2.1348424115474565}, |
| 59 | + {0.6593477498700266, -2.1351460576998926}, |
| 60 | + {0.6597155087395117, -2.1351049454274}, |
| 61 | + {0.6597337410387994, -2.135113899444683}, |
| 62 | + {0.6598277083823935, -2.1351065432309517}, |
| 63 | + {0.659837290351688, -2.1350919904836627}, |
| 64 | + {0.6598391300107502, -2.1350911731005957}, |
| 65 | + {0.6598335712627461, -2.1350732321630828}, |
| 66 | + {0.6597162034032434, -2.134664026354221}, |
| 67 | + {0.6596785831942451, -2.134651647657116}, |
| 68 | + {0.6596627824684727, -2.13458880305965}, |
| 69 | + {0.6596785832500957, -2.134530719130462}, |
| 70 | + {0.6596093592822273, -2.13428052987356}, |
| 71 | + {0.6596116166352313, -2.134221493755564}, |
| 72 | + {0.6595973199434513, -2.134146270344056}, |
| 73 | + {0.6595536764042369, -2.1340805688066653}, |
| 74 | + {0.6594611172376618, -2.133753252031165}, |
| 75 | + {0.6594829406269346, -2.1337342082305697}, |
| 76 | + {0.6594897134102581, -2.1337104032834757}, |
| 77 | + {0.6597920983773051, -2.1332343063312775}, |
| 78 | + {0.6597959342671712, -2.133241848488897}}; |
| 79 | +GeoLoop alamedaGeoLoop; |
| 80 | +GeoPolygon alamedaGeoPolygon; |
| 81 | + |
| 82 | +LatLng southernVerts[] = {{0.6367481147484843, -2.1290865397798906}, |
| 83 | + {0.6367481152301953, -2.129086539469222}, |
| 84 | + {0.6367550754426818, -2.128887436716856}, |
| 85 | + {0.6367816002113981, -2.1273204058681094}, |
| 86 | + {0.6380814125349741, -2.127201274803692}, |
| 87 | + {0.6388614350074809, -2.12552061082428}, |
| 88 | + {0.6393520289210095, -2.124274316938293}, |
| 89 | + {0.639524834205869, -2.122168447308359}, |
| 90 | + {0.6405714857447717, -2.122083222593005}, |
| 91 | + {0.640769478635285, -2.120979885974894}, |
| 92 | + {0.6418936996869471, -2.1147667448862255}, |
| 93 | + {0.6419094141707652, -2.1146521242709584}, |
| 94 | + {0.6269997808948107, -2.1038647304637257}, |
| 95 | + {0.6252080524974937, -2.1195521728170457}, |
| 96 | + {0.626379700264057, -2.1203708632511162}, |
| 97 | + {0.6282200029232767, -2.1210412050690723}, |
| 98 | + {0.6283657301211779, -2.1219496416754393}, |
| 99 | + {0.6305651783819565, -2.123628532238016}, |
| 100 | + {0.6308259852882764, -2.124225549648211}, |
| 101 | + {0.6317049665784865, -2.124887756638367}, |
| 102 | + {0.6323403882676475, -2.1266205835454053}, |
| 103 | + {0.6334397909415498, -2.1277211741619553}, |
| 104 | + {0.6367481147484843, -2.1290865397798906}}; |
| 105 | +GeoLoop southernGeoLoop; |
| 106 | +GeoPolygon southernGeoPolygon; |
| 107 | + |
| 108 | +BEGIN_BENCHMARKS(); |
| 109 | + |
| 110 | +sfGeoLoop.numVerts = 6; |
| 111 | +sfGeoLoop.verts = sfVerts; |
| 112 | +sfGeoPolygon.geoloop = sfGeoLoop; |
| 113 | + |
| 114 | +alamedaGeoLoop.numVerts = 50; |
| 115 | +alamedaGeoLoop.verts = alamedaVerts; |
| 116 | +alamedaGeoPolygon.geoloop = alamedaGeoLoop; |
| 117 | + |
| 118 | +southernGeoLoop.numVerts = 23; |
| 119 | +southernGeoLoop.verts = southernVerts; |
| 120 | +southernGeoPolygon.geoloop = southernGeoLoop; |
| 121 | + |
| 122 | +int64_t numHexagons; |
| 123 | +H3Index *hexagons; |
| 124 | + |
| 125 | +BENCHMARK(polygonToCellsSF, 500, { |
| 126 | + H3_EXPORT(maxPolygonToCellsSize)(&sfGeoPolygon, 9, 0, &numHexagons); |
| 127 | + hexagons = calloc(numHexagons, sizeof(H3Index)); |
| 128 | + H3_EXPORT(polygonToCellsExperimental)(&sfGeoPolygon, 9, 0, hexagons); |
| 129 | + free(hexagons); |
| 130 | +}); |
| 131 | + |
| 132 | +BENCHMARK(polygonToCellsAlameda, 500, { |
| 133 | + H3_EXPORT(maxPolygonToCellsSize)(&alamedaGeoPolygon, 9, 0, &numHexagons); |
| 134 | + hexagons = calloc(numHexagons, sizeof(H3Index)); |
| 135 | + H3_EXPORT(polygonToCellsExperimental)(&alamedaGeoPolygon, 9, 0, hexagons); |
| 136 | + free(hexagons); |
| 137 | +}); |
| 138 | + |
| 139 | +BENCHMARK(polygonToCellsSouthernExpansion, 10, { |
| 140 | + H3_EXPORT(maxPolygonToCellsSize)(&southernGeoPolygon, 9, 0, &numHexagons); |
| 141 | + hexagons = calloc(numHexagons, sizeof(H3Index)); |
| 142 | + H3_EXPORT(polygonToCellsExperimental)(&southernGeoPolygon, 9, 0, hexagons); |
| 143 | + free(hexagons); |
| 144 | +}); |
| 145 | + |
| 146 | +END_BENCHMARKS(); |
0 commit comments