Skip to content

Instantly share code, notes, and snippets.

@mosra
Created January 16, 2012 23:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mosra/1623547 to your computer and use it in GitHub Desktop.
Save mosra/1623547 to your computer and use it in GitHub Desktop.
Tipsify benchmark
queue<unsigned int> cache;
unordered_set<unsigned int> map;
size_t misses = 0;
size_t maxSize = 24;
for(unsigned int index: builder.indices()) {
if(map.find(index) != map.end()) continue;
/* Not in cache */
++misses;
/* Erase last element from cache */
if(cache.size() == maxSize) {
map.erase(cache.front());
cache.pop();
}
/* Put new element to cache */
cache.push(index);
map.insert(index);
}
Debug() << "Cache misses:" << misses << '/' << builder.indexCount();
buddha:
with: 66 853 / 300 000 (22%)
without: 230 792 / 300 000 (77%)
dragon:
with: 65 995 / 300 000 (22%)
without: 223 617 / 300 000 (75%)
bunny:
with: 43 578 / 208 998 (21%)
without: 143 718 / 208 998 (69%)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment