コード例 #1
0
ファイル: bench.c プロジェクト: bfdream/liquid-fpm
// run basic benchmark to estimate CPU clock frequency
void estimate_cpu_clock(void)
{
    printf("  estimating cpu clock frequency...\n");
    unsigned long int i, n = 1<<4;
    struct rusage start, finish;
    double extime;
    
    do {
        // trials
        n <<= 1;
        unsigned int x=0;
        getrusage(RUSAGE_SELF, &start);
        for (i=0; i<n; i++) {
            // perform mindless task
            x <<= 1;
            x |= 1;
            x &= 0xff;
            x ^= 0xff;
        }
        getrusage(RUSAGE_SELF, &finish);

        extime = calculate_execution_time(start, finish);
    } while (extime < 0.5 && n < (1<<28));

    // estimate cpu clock frequency
    cpu_clock = 23.9 * n / extime;

    printf("  performed %ld trials in %5.1f ms\n", n, extime * 1e3);
    
    float clock_format = cpu_clock;
    char clock_units = convert_units(&clock_format);
    printf("  estimated clock speed: %7.3f %cHz\n", clock_format, clock_units);
}
コード例 #2
0
ファイル: bench.c プロジェクト: bfdream/liquid-fpm
int main() {
    //
    struct rusage t0;
    struct rusage t1;
    unsigned long int n;
    double extime;
    double cycles_per_trial;
    unsigned int resolution = 256;
    float rmse;
    float maxe;

    estimate_cpu_clock();
    num_trials = (unsigned long int) ( cpu_clock / 1000 );
    num_trials = num_trials < 256 ? 256 : num_trials;
    
    unsigned int i;

    // run benchmarks
    for (i=0; i<NUM_BENCHMARKS; i++) {
        // run precision test
        benchmarks[i].precision_api(resolution,&rmse,&maxe);

        // run speed test
        n = num_trials;
        benchmarks[i].benchmark_api(&t0,&t1,&n);

        // compile results
        extime = calculate_execution_time(t0,t1);
        cycles_per_trial = extime * cpu_clock / (n);

        // print results
        printf("    %-20s : %10.6f s (%7.2f cycles/tr) : %10.8f rms, %10.8f max\n",
            benchmarks[i].name,
            extime,
            cycles_per_trial,
            rmse,
            maxe);
    }

    printf("done.\n");

    return 0;
}
コード例 #3
0
ファイル: newbench_example.c プロジェクト: Clivia/liquid-dsp
int main() {
    struct rusage start,finish;
    unsigned long int num_trials = 1000000;
    unsigned int n;
    unsigned int D;
    double extime;
    double cpuclock=2.4e9;
    double cycles_per_trial;
    struct decim_crcf_opts opts;
    for (D=2; D<=8; D*=2) {
        printf("***** D = %u\n",D);
        for (n=5; n<31; n+=4) {
            opts.D = D;
            opts.n = n;
            benchmark_decim_crcf((void*)(&opts),&start,&finish,&num_trials);
            extime = calculate_execution_time(start,finish);
            cycles_per_trial = cpuclock * extime / (double)(num_trials);
            printf("n : %3u, D : %3u, cycles/trial : %6.2f\n", n,D,cycles_per_trial);
        }
    }
    printf("done.\n");
    return 0;
}