int main() { int tidx = 1; int B256[256]; #if TIMSORT timsort(&Q256[0], &B256[0], 0, 256); test(tidx++, "timsort 256 elements", compare(&Q256[0], &A256[0], 256)); #else merge_sort(&Q256[0], &B256[0], 0, 256); test(tidx++, "merge sort 256 elements", compare(&Q256[0], &A256[0], 256)); #endif int B4096[4096]; #if TIMSORT timsort(&Q4096[0], &B4096[0], 0, 4096); test(tidx++, "timsort 4096 elements", compare(&Q4096[0], &A4096[0], 4096)); #else merge_sort(&Q4096[0], &B4096[0], 0, 4096); test(tidx++, "merge sort 4096 elements", compare(&Q4096[0], &A4096[0], 4096)); #endif return 0; }
void MainWindow::on_pushButton_2_clicked() { float timer = 0; if ( count > 1 && count < 1000 ) timer = timsort(masss, count); QString t = "time = "; t.append(QString::number(timer)); t.append(" seconds"); ui->time->setText(t); }
void run_tests(void) { int err; int test; TYPE *dst; size_t size; printf("Running tests\n"); #ifndef _WIN32 srand48(SEED); #endif #if 1 printf("timsort\n"); for (test = 0; test < TESTS; test++) { size = (lrand48() % (MAXSIZE + 1)); dst = malloc(size * sizeof(dst[0])); if (!dst && size) { perror("malloc failed"); exit(EXIT_FAILURE); } fill(dst, size); #ifdef USE_CMP_ARG err = timsort_r(dst, size, sizeof(dst[0]), compare_arg, NULL); #else err = timsort(dst, size, sizeof(dst[0]), compare); #endif if (err) { perror("timsort failed"); exit(EXIT_FAILURE); } verify(dst, size); #ifdef USE_CMP_ARG err = timsort_r(dst, size, sizeof(dst[0]), compare_arg, NULL); #else err = timsort(dst, size, sizeof(dst[0]), compare); #endif if (err) { perror("timsort failed"); exit(EXIT_FAILURE); } verify(dst, size); free(dst); } #else printf("mergesort\n"); for (test = 0; test < TESTS; test++) { size = (lrand48() % (MAXSIZE + 1)); dst = malloc(size * sizeof(dst[0])); if (!dst && size) { perror("malloc failed"); exit(EXIT_FAILURE); } fill(dst, size); err = mergesort(dst, size, sizeof(dst[0]), compare); if (err) { perror("mergesort failed"); exit(EXIT_FAILURE); } verify(dst, size); err = mergesort(dst, size, sizeof(dst[0]), compare); if (err) { perror("mergesort failed"); exit(EXIT_FAILURE); } verify(dst, size); free(dst); } #endif }
// Documented in header. void utilSortStable(void *base, size_t nel, size_t width, int (*compar)(const void *, const void *)) { timsort(base, nel, width, compar); }