Debian Codegraph @

terps/tads/tads3/test/data/rand_perf.t

raw
1 /*
2 * random number generator - performance test
3 */
4
5 #include "tads.h"
6 #include "t3.h"
7
8 class Throwable: object
9 // basic exception class
10 display = "basic exception object";
11 ;
12
13 class RuntimeError: Throwable
14 construct(errno, ...) { errno_ = errno; }
15 errno_ = 0
16 display = "RuntimeError: error = <<errno_>>"
17 ;
18
19 _say_embed(str) { tadsSay(str); }
20
21 _main(args)
22 {
23 t3SetSay(_say_embed);
24 try
25 {
26 main();
27 }
28 catch (Throwable th)
29 {
30 "\n\n*** Unhandled exception: << th.display >>\n";
31 }
32 }
33
34 main()
35 {
36 local i;
37 local buckets = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
38 local start;
39
40 randomize();
41
42 "Generating random numbers from 1 to 10...\n";
43 start = getTime(GetTimeTicks);
44 for (i = 0 ; i < 1000000 ; ++i)
45 {
46 local val;
47
48 val = rand(10) + 1;
49 ++buckets[val];
50 }
51 "Elapsed time: <<getTime(GetTimeTicks) - start>>\n";
52
53 "Number of values at each integer:\n";
54 for (i = 1 ; i <= 10 ; ++i)
55 " <<i>>: <<buckets[i]>>\n";
56 }
57