File: arrexpr1.cpp

package info (click to toggle)
blitz%2B%2B 1%3A0.10-3.2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 13,276 kB
  • ctags: 12,037
  • sloc: cpp: 70,465; sh: 11,116; fortran: 1,510; python: 1,246; f90: 852; makefile: 701
file content (85 lines) | stat: -rw-r--r-- 1,580 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Array expression benchmark

#include <blitz/array.h>
#include <blitz/benchext.h>

BZ_USING_NAMESPACE(blitz)

void blitzVersion(BenchmarkExt<int>& bench);
void CVersion(BenchmarkExt<int>& bench);

int main()
{
    BenchmarkExt<int> bench("Array expression", 2);

    bench.beginBenchmarking();
    blitzVersion(bench);
    CVersion(bench);
    bench.endBenchmarking();

    bench.saveMatlabGraph("arrexpr1.m");

    return 0;
}

void blitzVersion(BenchmarkExt<int>& bench)
{
    bench.beginImplementation("Blitz++");

    while (!bench.doneImplementationBenchmark())
    {
        int N = bench.getParameter();

        cout << "Blitz++: N = " << N << endl;

        long iters = bench.getIterations();

        Array<double,1> x(N);

        // Tickle
        x = 0.;
        firstIndex i;

        bench.start();
        for (long it=0; it < iters; ++it)
        {
            x = i * i;
        }
        bench.stop();
    }

    bench.endImplementation();
}

void CVersion(BenchmarkExt<int>& bench)
{
    bench.beginImplementation("C");

    while (!bench.doneImplementationBenchmark())
    {
        int N = bench.getParameter();

        cout << "C: N = " << N << endl;       

        long iters = bench.getIterations();

        double* x = new double[N];

        // Tickle
        for (int i=0; i < N; ++i)
            x[i] = 0;

        bench.start();
        for (long it=0; it < iters; ++it)
        {
            for (int i=0; i < N; ++i)
                x[i] = i * i;
        }
        bench.stop();

        delete [] x;
    }

    bench.endImplementation();
}