File: bench.e

package info (click to toggle)
euler 1.61.0-12
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 5,164 kB
  • sloc: ansic: 24,761; sh: 8,314; makefile: 141; cpp: 47; php: 1
file content (168 lines) | stat: -rw-r--r-- 2,553 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
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
.. Bench function.

comment

Run: test

Times for bench

OS/2, 486 DX 50/2, 8 MB
  40   9  88 209  49 262 311 175 131 143 105 585
OS/2, P90, 16 MB
  35   4  64 113  45 123 141  92  79  88  62 216
Windows 95, P75, 32 MB
   3   4  42 110  22 111 134  72  63  69  50 208
Windows NT, K6-2 500, 128 MB
  0.5  0.4 4 10  2.4 10 12  7.4  5.6  6.3  5.2  129

Benchmark is running ...

endcomment

function leer ()
	return 0;
endfunction

leert=0;

function bench (ffunction)
## bench("f",...) returns the time needed by f in milliseconds.
## ... is passed to f.
	global leert;
	func=ffunction;
	t=time(); count=0;
	repeat;
		if (time()>t+5); break; endif;
		func(args(2)); count=count+1;
	end;
	argt=(time()-t)/count;
	return argt;
endfunction

leert=bench("leer");

function f1
	loop 1 to 1000;
	end;
	return 0;
endfunction

function f2
	loop 1 to 1000;
		endif;
	end;
	return 0;
endfunction

function f3
	x=0;
	loop 1 to 1000;
		x=3;
	end;
	return 0;
endfunction

function f4
	x=0;
	loop 1 to 1000;
		x;
	end;
	return 0;
endfunction

function f5
	A=zeros([2,2]);
	loop 1 to 1000;
		A=[1,2;3,4];
	end;
	return 0;
endfunction

function f6
	A=zeros([2,2]);
	loop 1 to 1000;
		A[1,1]=A[1,2];
	end;
	return 0;
endfunction

function f7
	loop 1 to 1000;
		v=1:10;
	end;
	return 0;
endfunction

function f8
	v=1:10;
	loop 1 to 1000;
		v{4}=5;
	end;
	return 0;
endfunction

function f9
	x=3;
	loop 1 to 1000;
		(x+x)*(x+x);
	end;
	return 0;
endfunction

function f10
	v=1:10;
	x=0;
	loop 1 to 1000;
		x=v{4};
	end;
	return 0;
endfunction

function f11
	v=1:10;
	x=0;
	loop 1 to 1000;
		v*v;
	end;
	return 0;
endfunction

function f12
	x=2;
	loop 1 to 1000;
		x=sqrt(sin(log(exp(x))));
	end;
	return 0;
endfunction

looptime=bench("f1");

function musec (ffunction)
	global looptime;
	res=bench(ffunction,args(2))*1000-looptime;
	return {printf("%12.3f musec ",res),res};
endfunction

function test
	global looptime;
	looptime=0;
	shortformat();
	{text,looptime}=musec("f1");
	text|" for one loop.",
	musec("f2")|" for: endif;",
	musec("f3")|" for: x=3;",
	musec("f9")|" for: (x+x)*(x+x);",
	musec("f4")|" for: x;",
	musec("f5")|" for: A=[1,2;3,4];",
	musec("f6")|" for: A[1,1]=A[1,2];",
	musec("f7")|" for: v=1:10;",
	musec("f8")|" for: v{4}=3;",
	musec("f10")|" for: x=v{4};",
	musec("f11")|" for: v*v;",
	musec("f12")|" for: x=sqrt(sin(log(exp(x))));",
	looptime=0;
	return 0;
endfunction

test();