This file is indexed.

/usr/share/calc/sumtimes.cal is in apcalc-common 2.12.4.4-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*
 * sumtimes - runtimes evaluating sums & squares of large lists and mats
 *
 * Copyright (C) 2006  Ernest Bowen
 *
 * Calc is open software; you can redistribute it and/or modify it under
 * the terms of the version 2.1 of the GNU Lesser General Public License
 * as published by the Free Software Foundation.
 *
 * Calc is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU Lesser General
 * Public License for more details.
 *
 * A copy of version 2.1 of the GNU Lesser General Public License is
 * distributed with calc under the filename COPYING-LGPL.  You should have
 * received a copy with calc; if not, write to Free Software Foundation, Inc.
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 * @(#) $Revision: 30.1 $
 * @(#) $Id: sumtimes.cal,v 30.1 2007/03/16 11:09:54 chongo Exp $
 * @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/sumtimes.cal,v $
 *
 * Under source code control:	2006/06/22 17:29
 * File existed as early as:	2006
 *
 * Share and enjoy!  :-)	http://www.isthe.com/chongo/tech/comp/calc/
 */


global sumtimes_t0, sumtimes_t1, sumtimes_t2, sumtimes_t3;
global sumtimes_A, sumtimes_B;
config("tilde", 0),;

define timematsum(N) {
    local n, s, p, ptop;

    sumtimes_A = mat[N];

    for (n = 0; n < N; n++) sumtimes_A[n] = rand(N);

    ptop = &sumtimes_A[n-1];
    sumtimes_t0 = usertime();
    for (s = n = 0; n < N; n++) s += sumtimes_A[n];
    sumtimes_t1 = usertime();
    for (s = 0, p = &sumtimes_A[0]; p <= ptop; p++) s += *p;
    sumtimes_t2 = usertime();
    s = matsum(sumtimes_A);
    sumtimes_t3 = usertime();

    print "Matrix sum runtimes";
    printf('\tStandard "for" loop:\t\t%.4f\n', sumtimes_t1 - sumtimes_t0);
    printf('\t"For" loop using pointers:\t\t%.4f\n', sumtimes_t2 - sumtimes_t1);
    printf('\tUsing builtin "matsum":\t\t%.4f\n', sumtimes_t3 - sumtimes_t2);
}

define timelistsum(N) {
    local n, s;

    sumtimes_A = makelist(N);
    for (n = 0; n < N; n++) sumtimes_A[n] = rand(N);

    sumtimes_t0 = usertime();
    for (s = n = 0; n < N; n++) s += sumtimes_A[n];
    sumtimes_t1 = usertime();
    s = sum(sumtimes_A);
    sumtimes_t2 = usertime();
    print "List sum runtimes";
    printf('\tStandard "for" loop:\t\t%.4f\n', sumtimes_t1 - sumtimes_t0);
    printf('\tUsing builtin "sum":\t\t%.4f\n', sumtimes_t2 - sumtimes_t1);
}


define timematsort(N) {
    local n;

    sumtimes_A = mat[N];
    for (n = 0; n < N; n++) sumtimes_A[n] = rand(N);
    sumtimes_t0 = usertime();
    sort(sumtimes_A);
    sumtimes_t1 = usertime();
    printf('\tMatrix sort runtime:\t\t%.4f\n', sumtimes_t1 - sumtimes_t0);
}


define timelistsort(N) {
    local n;

    sumtimes_A = makelist(N);
    for (n = 0; n < N; n++) sumtimes_A[n] = rand(N);
    sumtimes_t0 = usertime();
    sort(sumtimes_A);
    sumtimes_t1 = usertime();
    printf('\tList sort runtime:\t\t%.4f\n', sumtimes_t1 - sumtimes_t0);
}

define timematreverse(N) {
    local n;

    sumtimes_A = mat[N];
    for (n = 0; n < N; n++) sumtimes_A[n] = rand(N);
    sumtimes_t0 = usertime();
    reverse(sumtimes_A);
    sumtimes_t1 = usertime();
    printf('\tMatrix reverse runtime        %.4f\n', sumtimes_t1 - sumtimes_t0);
}

define timelistreverse(N) {
    local n;

    sumtimes_A = makelist(N);
    for (n = 0; n < N; n++) sumtimes_A[n] = rand(N);
    sumtimes_t0 = usertime();
    reverse(sumtimes_A);
    sumtimes_t1 = usertime();
    printf('\tList reverse runtime:\t\t%.4f\n', sumtimes_t1 - sumtimes_t0);
}

define timematssq(N) {
    local n, s, p, ptop;

    sumtimes_A = mat[N];

    for (n = 0; n < N; n++) sumtimes_A[n] = rand(N);

    ptop = &sumtimes_A[n-1];
    sumtimes_t0 = usertime();
    for (s = n = 0; n < N; n++) s += sumtimes_A[n]^2;
    sumtimes_t1 = usertime();
    for (s = 0, p = &sumtimes_A[0]; p <= ptop; p++) s += (*p)^2;
    sumtimes_t2 = usertime();

    print "Matrix sum of squares runtimes";
    printf('\tStandard "for" loop:\t\t%.4f\n', sumtimes_t1 - sumtimes_t0);
    printf('\t"For" loop using pointers:\t\t%.4f\n', sumtimes_t2 - sumtimes_t1);
}

define timelistssq(N) {
    local n, s;

    sumtimes_A = makelist(N);
    for (n = 0; n < N; n++) sumtimes_A[n] = rand(N);

    sumtimes_t0 = usertime();
    for (s = n = 0; n < N; n++) s += sumtimes_A[n]^2;
    sumtimes_t1 = usertime();
    s = ssq(sumtimes_A);
    sumtimes_t2 = usertime();
    print "List sum of squares runtimes";
    printf('\tStandard "for" loop:\t\t%.4f\n', sumtimes_t1 - sumtimes_t0);
    printf('\tUsing builtin "ssq":\t\t%.4f\n', sumtimes_t2 - sumtimes_t1);
}

define timehmean(N, M = 10) {
    local n, s, v1, v2;

    sumtimes_A = makelist(N);
    for (n = 0; n < N; n++) sumtimes_A[n] = rand(1, M);

    sumtimes_t0 = usertime();
    for (s = n = 0; n < N; n++) s += 1/sumtimes_A[n];
    v1 = N/s;
    sumtimes_t1 = usertime();
    v2 = hmean(sumtimes_A);
    sumtimes_t2 = usertime();
    print v1, v2;
    print "List harmonic meanruntimes";
    printf('\tStandard "for" loop:\t\t%.4f\n', sumtimes_t1 - sumtimes_t0);
    printf('\tUsing builtin "hmean":\t\t%.4f\n', sumtimes_t2 - sumtimes_t1);
}

define doalltimes(N) {
    timematsum(N);
    print;
    timelistsum(N);
    print;
    timematssq(N);
    print;
    timelistssq(N);
    print;
    timematsort(N);
    timelistsort(N);
    timematreverse(N);
    timelistreverse(N);
    print;
}