Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- m[key] = val;
- m.insert(make_pair(key, val));
- m[key] = val;
- m.insert(make_pair(key, val));
- #include <map>
- #include <iostream>
- #include <ctime>
- #include <string>
- using namespace std;
- typedef map <unsigned int,string> MapType;
- const unsigned int NINSERTS = 1000000;
- int main() {
- MapType m1;
- string s = "foobar";
- clock_t t = clock();
- for ( unsigned int i = 0; i < NINSERTS; i++ ) {
- m1[i] = s;
- }
- cout << clock() - t << endl;
- MapType m2;
- t = clock();
- for ( unsigned int i = 0; i < NINSERTS; i++ ) {
- m2.insert( make_pair( i, s ) );
- }
- cout << clock() - t << endl;
- }
- 1547
- 1453
Add Comment
Please, Sign In to add comment