adding benchmarks and readme
This commit is contained in:
committed by
JamesFlare1212
parent
186a7e60ea
commit
95d9bb50ca
20
lectures/optimization/map_erase/map_erase_fast.cpp
Normal file
20
lectures/optimization/map_erase/map_erase_fast.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
|
||||
int main() {
|
||||
const int N = 1000000;
|
||||
std::map<int, int> m;
|
||||
|
||||
// fill the map with some values
|
||||
for (int i = 0; i < N; ++i) {
|
||||
m[i] = i;
|
||||
}
|
||||
|
||||
// erase all elements using iterators
|
||||
for (std::map<int, int>::iterator itr = m.begin(); itr != m.end(); ) {
|
||||
itr = m.erase(itr); // erase using iterator and move to the next element
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user