#include #include #include #include #include #include #include #define N 1000000 #define MIN_LEN 20 #define MAX_LEN 50 #define MAX_CHAR 'z' int main(void) { srand(time(NULL)); timeval tv; std::string s[N]; char buf[MAX_LEN + 1]; // Generate some strings for (int i = 0; i < N; i++) { int len = rand() % (MAX_LEN - MIN_LEN + 1) + MIN_LEN; for (int j = 0; j < len; j++) { buf[j] = rand() % (MAX_CHAR - 'a' + 1) + 'a'; } buf[len] = '\0'; s[i] = buf; } gettimeofday (&tv, NULL); long long t1 = 1000LL * tv.tv_sec + tv.tv_usec / 1000; std::sort(s, s + N); gettimeofday (&tv, NULL); long long t2 = 1000LL * tv.tv_sec + tv.tv_usec / 1000; printf("Timp: %lld ms\n", t2 - t1); // Print them // for (int i = 0; i < N; i++) { // cout << s[i].length() << "[" << s[i] << "]\n"; // } }