| | 1 | #include "tads.h" |
| | 2 | #include "t3.h" |
| | 3 | #include "bignum.h" |
| | 4 | |
| | 5 | #define time_start(msg) \ |
| | 6 | { tadsSay(msg); "...\n"; local ts__ = getTime(GetTimeTicks); |
| | 7 | #define time_end \ |
| | 8 | ts__ = getTime(GetTimeTicks) - ts__; "\n...done: time = <<ts__>> ms\b"; } |
| | 9 | |
| | 10 | main(args) |
| | 11 | { |
| | 12 | local i; |
| | 13 | local x, y; |
| | 14 | local iter = 100; |
| | 15 | |
| | 16 | x = new BigNumber('2.53000000'); |
| | 17 | |
| | 18 | time_start('exp'); |
| | 19 | for (i = 1 ; i < iter ; ++i) |
| | 20 | y = x.expE(); |
| | 21 | time_end; |
| | 22 | |
| | 23 | time_start('log'); |
| | 24 | for (i = 1 ; i < iter ; ++i) |
| | 25 | y = x.logE(); |
| | 26 | time_end; |
| | 27 | |
| | 28 | time_start('sinh'); |
| | 29 | for (i = 1 ; i < iter ; ++i) |
| | 30 | y = x.sinh(); |
| | 31 | time_end; |
| | 32 | |
| | 33 | time_start('cosh'); |
| | 34 | for (i = 1 ; i < iter ; ++i) |
| | 35 | y = x.cosh(); |
| | 36 | time_end; |
| | 37 | |
| | 38 | time_start('tanh'); |
| | 39 | for (i = 1 ; i < iter ; ++i) |
| | 40 | y = x.tanh(); |
| | 41 | time_end; |
| | 42 | |
| | 43 | "done!\n"; |
| | 44 | } |
| | 45 | |
| | 46 | preinit() |
| | 47 | { |
| | 48 | } |
| | 49 | |
| | 50 | |
| | 51 | /* ------------------------------------------------------------------------ */ |
| | 52 | /* |
| | 53 | * some boilerplate setup stuff |
| | 54 | */ |
| | 55 | |
| | 56 | class Exception: object |
| | 57 | display = "Unknown exception" |
| | 58 | ; |
| | 59 | |
| | 60 | class RuntimeError: Exception |
| | 61 | construct(errno, ...) { errno_ = errno; } |
| | 62 | display = "Runtime error: <<exceptionMessage>>" |
| | 63 | errno_ = 0 |
| | 64 | exceptionMessage = '' |
| | 65 | ; |
| | 66 | |
| | 67 | _say_embed(str) { tadsSay(str); } |
| | 68 | |
| | 69 | _main(args) |
| | 70 | { |
| | 71 | try |
| | 72 | { |
| | 73 | t3SetSay(&_say_embed); |
| | 74 | if (!global.preinited_) |
| | 75 | { |
| | 76 | preinit(); |
| | 77 | global.preinited_ = true; |
| | 78 | } |
| | 79 | if (!t3GetVMPreinitMode()) |
| | 80 | main(args); |
| | 81 | } |
| | 82 | catch (RuntimeError rte) |
| | 83 | { |
| | 84 | "\n<<rte.display>>\n"; |
| | 85 | } |
| | 86 | } |
| | 87 | |
| | 88 | global: object |
| | 89 | preinited_ = nil |
| | 90 | ; |