CharCalls.java revision 381:b6d6877c1155
1292068Ssjg/* 2246149Ssjg * Copyright 2000-2008 Sun Microsystems, Inc. All Rights Reserved. 3246149Ssjg * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4246149Ssjg * 5246149Ssjg * This code is free software; you can redistribute it and/or modify it 6246149Ssjg * under the terms of the GNU General Public License version 2 only, as 7246149Ssjg * published by the Free Software Foundation. 8246149Ssjg * 9246149Ssjg * This code is distributed in the hope that it will be useful, but WITHOUT 10246149Ssjg * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11246149Ssjg * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12246149Ssjg * version 2 for more details (a copy is included in the LICENSE file that 13246149Ssjg * accompanied this code). 14246149Ssjg * 15246149Ssjg * You should have received a copy of the GNU General Public License version 16246149Ssjg * 2 along with this work; if not, write to the Free Software Foundation, 17246149Ssjg * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18246149Ssjg * 19246149Ssjg * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 20246149Ssjg * CA 95054 USA or visit www.sun.com if you need additional information or 21246149Ssjg * have any questions. 22246149Ssjg */ 23246149Ssjg 24246149Ssjg/* 25246149Ssjg * 26246149Ssjg */ 27246149Ssjg 28246149Ssjgpackage bench.rmi; 29246149Ssjg 30246149Ssjgimport bench.Benchmark; 31246149Ssjgimport java.rmi.Remote; 32246149Ssjgimport java.rmi.RemoteException; 33246149Ssjgimport java.rmi.server.UnicastRemoteObject; 34246149Ssjg 35246149Ssjg/** 36246149Ssjg * Benchmark for testing speed of calls with char arguments/return values. 37246149Ssjg */ 38246149Ssjgpublic class CharCalls implements Benchmark { 39246149Ssjg 40246149Ssjg interface Server extends Remote { 41246149Ssjg public char call(char val) throws RemoteException; 42246149Ssjg } 43246149Ssjg 44246149Ssjg static class ServerImpl extends UnicastRemoteObject implements Server { 45246149Ssjg public ServerImpl() throws RemoteException { 46246149Ssjg } 47246149Ssjg 48246149Ssjg public char call(char val) throws RemoteException { 49246149Ssjg return val; 50246149Ssjg } 51246149Ssjg } 52246149Ssjg 53246149Ssjg static class ServerFactory implements BenchServer.RemoteObjectFactory { 54246149Ssjg public Remote create() throws RemoteException { 55246149Ssjg return new ServerImpl(); 56246149Ssjg } 57246149Ssjg } 58246149Ssjg 59246149Ssjg /** 60246149Ssjg * Issue char calls. 61246149Ssjg * Arguments: <# calls> 62246149Ssjg */ 63246149Ssjg public long run(String[] args) throws Exception { 64246149Ssjg int cycles = Integer.parseInt(args[0]); 65246149Ssjg BenchServer bsrv = Main.getBenchServer(); 66246149Ssjg Server stub = (Server) bsrv.create(new ServerFactory()); 67246149Ssjg 68246149Ssjg long start = System.currentTimeMillis(); 69246149Ssjg for (int i = 0; i < cycles; i++) 70246149Ssjg stub.call('0'); 71246149Ssjg long time = System.currentTimeMillis() - start; 72246149Ssjg 73246149Ssjg bsrv.unexport(stub, true); 74246149Ssjg return time; 75246149Ssjg } 76246149Ssjg} 77246149Ssjg