3 * Copyright (c) 1996, 1997 by Doug Bell <dbell@shvn.com>. All Rights Reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 // This file has been hacked to compile without the rest of the
31 class OperatorBenchmark
{
33 public int getSampleCount() { return 0; }
34 public int getSampleMillis() { return 0; }
37 public void startTest () { }
38 public long finishTest () { return 0; }
39 public void startTimer (boolean b
) { }
40 public void stopTimer (int a
, int b
) { }
41 public void report (String s
) { }
42 public void println (String s
) { }
44 public int getTestTime () {
45 return (int) (100 * getSampleCount() * getSampleMillis()) / 1000;
48 public int getRunningTime () {
49 return (int) (1.1 * getTestTime());
52 public long runTest () {
53 int dummy1
= 0, dummy2
= 0, dummy3
= 0; // occupy implicit index slots
55 byte b1
= 1, b2
= 2, b3
= 3;
56 short s1
= 1, s2
= 2, s3
= 3;
57 int i1
= 1, i2
= 2, i3
= 3;
58 long l1
= 1, l2
= 2, l3
= 3;
59 float f1
= 1, f2
= 2, f3
= 3;
60 double d1
= 1, d2
= 2, d3
= 3;
64 println("--- byte operators, local vars");
66 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
68 for (ii
= 0; go
; ii
++)
74 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
76 for (ii
= 0; go
; ii
++)
80 report("byte += byte");
82 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
84 for (ii
= 0; go
; ii
++)
85 b1
= (byte) (b2
+ b3
);
88 report("byte = byte + byte");
90 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
92 for (ii
= 0; go
; ii
++)
96 report("byte *= byte");
98 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
100 for (ii
= 0; go
; ii
++)
101 b1
= (byte) (b2
* b3
);
104 report("byte = byte * byte");
106 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
108 for (ii
= 0; go
; ii
++)
114 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
116 for (ii
= 0; go
; ii
++)
120 report("byte <<= 1");
122 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
124 for (ii
= 0; go
; ii
++)
128 report("byte %= byte");
130 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
132 for (ii
= 0; go
; ii
++)
133 b1
= (byte) (b2
% b3
);
136 report("byte = byte % byte");
138 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
140 for (ii
= 0; go
; ii
++)
144 report("byte /= byte");
146 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
148 for (ii
= 0; go
; ii
++)
149 b1
= (byte) (b2
/ b3
);
152 report("byte = byte / byte");
154 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
156 for (ii
= 0; go
; ii
++)
162 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
164 for (ii
= 0; go
; ii
++)
168 report("byte >>= 1");
170 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
172 for (ii
= 0; go
; ii
++)
176 report("byte >>= int");
178 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
180 for (ii
= 0; go
; ii
++)
181 b1
= (byte) (b2
>> i3
);
184 report("byte = byte >> int");
186 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
188 for (ii
= 0; go
; ii
++)
192 report("byte |= byte");
194 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
196 for (ii
= 0; go
; ii
++)
197 b1
= (byte) (b2
| b3
);
200 report("byte = byte | byte");
202 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
204 for (ii
= 0; go
; ii
++)
208 report("byte &= byte");
210 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
212 for (ii
= 0; go
; ii
++)
213 b1
= (byte) (b2
& b3
);
216 report("byte = byte & byte");
218 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
220 for (ii
= 0; go
; ii
++)
224 report("byte ^= byte");
226 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
228 for (ii
= 0; go
; ii
++)
229 b1
= (byte) (b2 ^ b3
);
232 report("byte = byte ^ byte");
235 println("--- short operators, local vars");
237 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
239 for (ii
= 0; go
; ii
++)
245 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
247 for (ii
= 0; go
; ii
++)
251 report("short += short");
253 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
255 for (ii
= 0; go
; ii
++)
256 s1
= (short) (s2
+ s3
);
259 report("short = short + short");
261 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
263 for (ii
= 0; go
; ii
++)
267 report("short *= short");
269 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
271 for (ii
= 0; go
; ii
++)
272 s1
= (short) (s2
* s3
);
275 report("short = short * short");
277 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
279 for (ii
= 0; go
; ii
++)
283 report("short *= 2");
285 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
287 for (ii
= 0; go
; ii
++)
291 report("short <<= 1");
293 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
295 for (ii
= 0; go
; ii
++)
299 report("short %= short");
301 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
303 for (ii
= 0; go
; ii
++)
304 s1
= (short) (s2
% s3
);
307 report("short = short % short");
309 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
311 for (ii
= 0; go
; ii
++)
315 report("short /= short");
317 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
319 for (ii
= 0; go
; ii
++)
320 s1
= (short) (s2
/ s3
);
323 report("short = short / short");
325 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
327 for (ii
= 0; go
; ii
++)
331 report("short /= 2");
333 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
335 for (ii
= 0; go
; ii
++)
339 report("short >>= 1");
341 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
343 for (ii
= 0; go
; ii
++)
347 report("short >>= int");
349 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
351 for (ii
= 0; go
; ii
++)
352 s1
= (short) (s2
>> i3
);
355 report("short = short >> int");
357 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
359 for (ii
= 0; go
; ii
++)
363 report("short |= short");
365 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
367 for (ii
= 0; go
; ii
++)
368 s1
= (short) (s2
| s3
);
371 report("short = short | short");
373 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
375 for (ii
= 0; go
; ii
++)
379 report("short &= short");
381 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
383 for (ii
= 0; go
; ii
++)
384 s1
= (short) (s2
& s3
);
387 report("short = short & short");
389 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
391 for (ii
= 0; go
; ii
++)
395 report("short ^= short");
397 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
399 for (ii
= 0; go
; ii
++)
400 s1
= (short) (s2 ^ s3
);
403 report("short = short ^ short");
406 println("--- int operators, local vars");
408 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
410 for (ii
= 0; go
; ii
++)
416 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
418 for (ii
= 0; go
; ii
++)
422 report("int += int");
424 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
426 for (ii
= 0; go
; ii
++)
430 report("int = int + int");
432 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
434 for (ii
= 0; go
; ii
++)
438 report("int *= int");
440 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
442 for (ii
= 0; go
; ii
++)
446 report("int = int * int");
448 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
450 for (ii
= 0; go
; ii
++)
456 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
458 for (ii
= 0; go
; ii
++)
464 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
466 for (ii
= 0; go
; ii
++)
470 report("int %= int");
472 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
474 for (ii
= 0; go
; ii
++)
478 report("int = int % int");
480 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
482 for (ii
= 0; go
; ii
++)
486 report("int /= int");
488 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
490 for (ii
= 0; go
; ii
++)
494 report("int = int / int");
496 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
498 for (ii
= 0; go
; ii
++)
504 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
506 for (ii
= 0; go
; ii
++)
512 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
514 for (ii
= 0; go
; ii
++)
518 report("int >>= int");
520 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
522 for (ii
= 0; go
; ii
++)
526 report("int = int >> int");
528 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
530 for (ii
= 0; go
; ii
++)
534 report("int |= int");
536 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
538 for (ii
= 0; go
; ii
++)
542 report("int = int | int");
544 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
546 for (ii
= 0; go
; ii
++)
550 report("int &= int");
552 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
554 for (ii
= 0; go
; ii
++)
558 report("int = int & int");
560 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
562 for (ii
= 0; go
; ii
++)
566 report("int ^= int");
568 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
570 for (ii
= 0; go
; ii
++)
574 report("int = int ^ int");
577 println("--- long operators, local vars");
579 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
581 for (ii
= 0; go
; ii
++)
587 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
589 for (ii
= 0; go
; ii
++)
593 report("long += long");
595 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
597 for (ii
= 0; go
; ii
++)
601 report("long = long + long");
603 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
605 for (ii
= 0; go
; ii
++)
609 report("long *= long");
611 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
613 for (ii
= 0; go
; ii
++)
617 report("long = long * long");
619 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
621 for (ii
= 0; go
; ii
++)
627 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
629 for (ii
= 0; go
; ii
++)
633 report("long <<= 1");
635 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
637 for (ii
= 0; go
; ii
++)
641 report("long %= long");
643 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
645 for (ii
= 0; go
; ii
++)
649 report("long = long % long");
651 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
653 for (ii
= 0; go
; ii
++)
657 report("long /= long");
659 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
661 for (ii
= 0; go
; ii
++)
665 report("long = long / long");
667 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
669 for (ii
= 0; go
; ii
++)
675 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
677 for (ii
= 0; go
; ii
++)
681 report("long >>= 1");
683 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
685 for (ii
= 0; go
; ii
++)
689 report("long >>= int");
691 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
693 for (ii
= 0; go
; ii
++)
697 report("long = long >> int");
699 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
701 for (ii
= 0; go
; ii
++)
705 report("long |= long");
707 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
709 for (ii
= 0; go
; ii
++)
713 report("long = long | long");
715 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
717 for (ii
= 0; go
; ii
++)
721 report("long &= long");
723 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
725 for (ii
= 0; go
; ii
++)
729 report("long = long & long");
731 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
733 for (ii
= 0; go
; ii
++)
737 report("long ^= long");
739 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
741 for (ii
= 0; go
; ii
++)
745 report("long = long ^ long");
748 println("--- float operators, local vars");
750 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
752 for (ii
= 0; go
; ii
++)
756 report("float += float");
758 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
760 for (ii
= 0; go
; ii
++)
761 f1
= (float) (f2
+ f3
);
764 report("float = float + float");
766 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
768 for (ii
= 0; go
; ii
++)
772 report("float *= float");
774 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
776 for (ii
= 0; go
; ii
++)
777 f1
= (float) (f2
* f3
);
780 report("float = float * float");
782 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
784 for (ii
= 0; go
; ii
++)
788 report("float %= float");
790 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
792 for (ii
= 0; go
; ii
++)
793 f1
= (float) (f2
% f3
);
796 report("float = float % float");
798 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
800 for (ii
= 0; go
; ii
++)
804 report("float /= float");
806 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
808 for (ii
= 0; go
; ii
++)
809 f1
= (float) (f2
/ f3
);
812 report("float = float / float");
815 println("--- double operators, local vars");
817 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
819 for (ii
= 0; go
; ii
++)
823 report("double += double");
825 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
827 for (ii
= 0; go
; ii
++)
831 report("double = double + double");
833 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
835 for (ii
= 0; go
; ii
++)
839 report("double *= double");
841 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
843 for (ii
= 0; go
; ii
++)
847 report("double = double * double");
849 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
851 for (ii
= 0; go
; ii
++)
855 report("double %= double");
857 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
859 for (ii
= 0; go
; ii
++)
863 report("double = double % double");
865 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
867 for (ii
= 0; go
; ii
++)
871 report("double /= double");
873 for (cnt
= getSampleCount(); --cnt
>= 0; ) {
875 for (ii
= 0; go
; ii
++)
879 report("double = double / double");
881 useint
[0] = dummy1
; useint
[1] = dummy2
; useint
[2] = dummy3
;
884 } // class OperatorBenchmark