Last active
August 29, 2015 14:06
-
-
Save yinqiwen/c6d0be258356996bd16b to your computer and use it in GitHub Desktop.
geohash encode/decode performance compare
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Code: | |
int main() | |
{ | |
GeoHashBits hash, fast_hash; | |
GeoHashNeighbors neighbors; | |
GeoHashRange lat_range, lon_range; | |
lat_range.max = 20037726.37; | |
lat_range.min = -20037726.37; | |
lon_range.max = 20037726.37; | |
lon_range.min = -20037726.37; | |
double radius = 5000; | |
double latitude = 9741705.20; | |
double longitude = 5417390.90; | |
uint32_t loop = 10000000; | |
uint32_t i = 0; | |
uint64_t start = get_current_epoch_millis(); | |
for (i = 0; i < loop; i++) | |
{ | |
geohash_encode(lat_range, lon_range, latitude, longitude, 24, &hash); | |
} | |
uint64_t end = get_current_epoch_millis(); | |
printf("Cost %llums to encode\n", end - start); | |
start = get_current_epoch_millis(); | |
for (i = 0; i < loop; i++) | |
{ | |
geohash_fast_encode(lat_range, lon_range, latitude, longitude, 24, &fast_hash); | |
} | |
end = get_current_epoch_millis(); | |
printf("Cost %llums to fast encode\n", end - start); | |
GeoHashArea area, area1; | |
start = get_current_epoch_millis(); | |
for (i = 0; i < loop; i++) | |
{ | |
geohash_decode(lat_range, lon_range, hash, &area); | |
} | |
end = get_current_epoch_millis(); | |
printf("Cost %llums to decode\n", end - start); | |
start = get_current_epoch_millis(); | |
for (i = 0; i < loop; i++) | |
{ | |
geohash_fast_decode(lat_range, lon_range, hash, &area1); | |
} | |
end = get_current_epoch_millis(); | |
printf("Cost %llums to fast decode\n", end - start); | |
return 0; | |
} | |
Run at same machine with different version compiler, different optimize flag | |
gcc 4.8.2 linux 2.6.32 | |
compile with -O2 | |
Cost 1912ms to encode | |
Cost 445ms to fast encode | |
Cost 1948ms to decode | |
Cost 927ms to fast decode | |
compile with -O0 | |
Cost 3628ms to encode | |
Cost 716ms to fast encode | |
Cost 6475ms to decode | |
Cost 949ms to fast decode | |
gcc 3.4.5 linux 2.6.32 | |
compile with -O2 | |
Cost 2935ms to encode | |
Cost 526ms to fast encode | |
Cost 1823ms to decode | |
Cost 1937ms to fast decode //slower | |
compile with -O0 | |
Cost 6964ms to encode | |
Cost 1245ms to fast encode | |
Cost 10288ms to decode | |
Cost 2740ms to fast decode | |
Update: use simple divide/shift operations instead of math function 'ldexp' | |
gcc 4.8.2 linux 2.6.32 | |
compile with -O2 | |
Cost 1235ms to encode | |
Cost 282ms to fast encode | |
Cost 1236ms to decode | |
Cost 195ms to fast decode | |
compile with -O0 | |
Cost 3653ms to encode | |
Cost 719ms to fast encode | |
Cost 6486ms to decode | |
Cost 620ms to fast decode | |
gcc 3.4.5 linux 2.6.32 | |
compile with -O2 | |
Cost 2950ms to encode | |
Cost 546ms to fast encode | |
Cost 2101ms to decode | |
Cost 400ms to fast decode | |
compile with -O0 | |
Cost 6984ms to encode | |
Cost 1241ms to fast encode | |
Cost 10555ms to decode | |
Cost 1495ms to fast decode | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Unfortunately in my working company, gcc 3.4.5 is widely used, most application compiled by it.