KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > trove > benchmark > Repeater


1 ///////////////////////////////////////////////////////////////////////////////
2
// Copyright (c) 2001, Eric D. Friedman All Rights Reserved.
3
//
4
// This library is free software; you can redistribute it and/or
5
// modify it under the terms of the GNU Lesser General Public
6
// License as published by the Free Software Foundation; either
7
// version 2.1 of the License, or (at your option) any later version.
8
//
9
// This library is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU Lesser General Public
15
// License along with this program; if not, write to the Free Software
16
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
///////////////////////////////////////////////////////////////////////////////
18

19 package gnu.trove.benchmark;
20
21 class Repeater implements Timer {
22     int _count;
23     Operation _operation;
24
25     Repeater(Operation o) {
26         _count = o.getIterationCount();
27         _operation = o;
28     }
29
30     public Result run() {
31         long theirs = theirs();
32         long ours = ours();
33         Result r = new Result();
34         r.setTheirs(theirs);
35         r.setOurs(ours);
36         r.setIterations(_count);
37         r.setDescription(_operation.toString());
38         return r;
39     }
40
41     public long theirs() {
42         long then = System.currentTimeMillis();
43         for (int i = 0; i < _count; i++) {
44             _operation.theirs();
45         }
46         long now = System.currentTimeMillis();
47         return (now -then);
48     }
49
50     public long ours() {
51         long then = System.currentTimeMillis();
52         for (int i = 0; i < _count; i++) {
53             _operation.ours();
54         }
55         long now = System.currentTimeMillis();
56         return (now -then);
57     }
58
59     public Operation getOperation() {
60         return _operation;
61     }
62 }
63
Popular Tags