コード例 #1
0
int main(int argc, char **argv) {
    // binsearch [random-seed]
    if (argc > 1) srand(atoi(argv[1]));

#ifdef POWER_OF_TWO
    size_t lengths[] = {
        256, 1024, 256 * 256, 256 * 1024,
        1024*1024, 16*1024*1024, 256*1024*1024
    };
#else
    size_t lengths[] = {
        100, 1000, 10*1000, 100*1000,
        1000*1000, 10*1000*1000, 100*1000*1000
    };
#endif

    size_t batches[] = { // batch sizes reduced to target count as needed
        1, 2, 4, 6, 8, 10, 12, 14, 16, 20,
        40, 60, 100, 200, 400, 1000, UINT32_MAX
    };

    for (size_t n = 0; n < COUNT(lengths); n++) {
        size_t length = lengths[n];
        size_t count = 1000*1000;
        size_t i;
        uint32_t *targets = create_search_targets(count, 2*length);
        printf("%zd Targets with Array Length", count);
        fflush(NULL);

        uint32_t *array = create_sorted_array(length, 2*length);
        printf(" %zd\n", length);

        size_t *reference_indexes = malloc(count * sizeof(size_t));
#ifdef LINEAR_REFERENCE
        linear_search(array, length,
                      targets, reference_indexes, count);
#else
        parallel_search(array, length,
                        targets, reference_indexes, count);
#endif

        size_t *indexes = malloc(count * sizeof(*indexes));
        for (i = 0; i < COUNT(batches); i++) {
            size_t batch = batches[i];
            size_t c;
            float cycles_per_search;
            memset(indexes, 0, count * sizeof(*indexes));
            if (batch > count) batch = count;
            printf("  Batch %3zd: ", batch);
            fflush(NULL);
            uint64_t cycles_start, cycles_final;
            RDTSC_START(cycles_start);
            for (c = 0; c < count; c += batch) {
                // possible smaller batch for last iteration
                if (c > count - batch) batch = count % batch;
                parallel_search(array, length, targets + c,
                                indexes + c, batch);
            }
            RDTSC_FINAL(cycles_final);
            cycles_per_search =
                (cycles_final - cycles_start) / (float) count;
            printf("cmov?: %.2f cycles/search ", cycles_per_search);
            verify_indexes(reference_indexes, indexes, count,
                           array, targets, length);

            RDTSC_START(cycles_start);
            for (c = 0; c < count; c += batch) {
                // possible smaller batch for last iteration
                if (c > count - batch) batch = count % batch;
                portable_parallel_search(array, length, targets + c,
                                indexes + c, batch);
            }
            RDTSC_FINAL(cycles_final);
            cycles_per_search =
                (cycles_final - cycles_start) / (float) count;
            printf(", portable: %.2f cycles/search", cycles_per_search);
            RDTSC_START(cycles_start);
            for (size_t c = 0; c < count; c += batch) {
                // possible smaller batch for last iteration
                if (c > count - batch) batch = count % batch;
                portable_parallel_search2(array, length, targets + c,
                                indexes + c, batch);
            }
            RDTSC_FINAL(cycles_final);
            cycles_per_search =
                (cycles_final - cycles_start) / (float) count;
            printf(", portable2: %.2f cycles/search", cycles_per_search);

            printf("\n");

        }
        free(array);
        free(targets);
        free(indexes);
        free(reference_indexes);
        printf("\n");
    }
}
コード例 #2
0
ファイル: jitsymbol.c プロジェクト: crossbuild/oprofile
/* allocate, populate and sort the jitentry arrays */
void create_arrays(void)
{
	max_entry_count = entry_count = count_entries();
	entries_symbols_ascending = create_sorted_array(cmp_symbolname);
	entries_address_ascending = create_sorted_array(cmp_address);
}