ByteArrayCalls.java revision 2362:00cd9dc3c2b5
167754Smsmith/* 267754Smsmith * Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved. 377424Smsmith * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4123315Snjl * 567754Smsmith * This code is free software; you can redistribute it and/or modify it 667754Smsmith * under the terms of the GNU General Public License version 2 only, as 767754Smsmith * published by the Free Software Foundation. 867754Smsmith * 967754Smsmith * This code is distributed in the hope that it will be useful, but WITHOUT 1067754Smsmith * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1167754Smsmith * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12114237Snjl * version 2 for more details (a copy is included in the LICENSE file that 1370243Smsmith * accompanied this code). 1467754Smsmith * 1567754Smsmith * You should have received a copy of the GNU General Public License version 1667754Smsmith * 2 along with this work; if not, write to the Free Software Foundation, 1767754Smsmith * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1867754Smsmith * 1967754Smsmith * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2067754Smsmith * or visit www.oracle.com if you need additional information or have any 2167754Smsmith * questions. 2267754Smsmith */ 2367754Smsmith 2467754Smsmith/* 2567754Smsmith * 2667754Smsmith */ 2767754Smsmith 2867754Smsmithpackage bench.rmi; 2967754Smsmith 3067754Smsmithimport bench.Benchmark; 3167754Smsmithimport java.rmi.Remote; 3267754Smsmithimport java.rmi.RemoteException; 3367754Smsmithimport java.rmi.server.UnicastRemoteObject; 3467754Smsmith 3567754Smsmith/** 3667754Smsmith * Benchmark for testing speed of calls with byte array arguments and 3767754Smsmith * return values. 3867754Smsmith */ 3967754Smsmithpublic class ByteArrayCalls implements Benchmark { 4067754Smsmith 4167754Smsmith interface Server extends Remote { 4267754Smsmith public byte[] call(byte[] a) throws RemoteException; 4367754Smsmith } 4467754Smsmith 4567754Smsmith static class ServerImpl extends UnicastRemoteObject implements Server { 4667754Smsmith public ServerImpl() throws RemoteException { 4767754Smsmith } 4867754Smsmith 4967754Smsmith public byte[] call(byte[] a) throws RemoteException { 5067754Smsmith return a; 5167754Smsmith } 5267754Smsmith } 5367754Smsmith 5467754Smsmith static class ServerFactory implements BenchServer.RemoteObjectFactory { 5567754Smsmith public Remote create() throws RemoteException { 5667754Smsmith return new ServerImpl(); 5767754Smsmith } 5867754Smsmith } 5967754Smsmith 6067754Smsmith /** 6167754Smsmith * Issue byte array calls. 6267754Smsmith * Arguments: <array size> <# calls> 6367754Smsmith */ 6467754Smsmith public long run(String[] args) throws Exception { 6567754Smsmith int size = Integer.parseInt(args[0]); 6667754Smsmith int reps = Integer.parseInt(args[1]); 6767754Smsmith BenchServer bsrv = Main.getBenchServer(); 6867754Smsmith Server stub = (Server) bsrv.create(new ServerFactory()); 6967754Smsmith byte[] array = new byte[size]; 7067754Smsmith 7167754Smsmith long start = System.currentTimeMillis(); 7267754Smsmith for (int i = 0; i < reps; i++) 7367754Smsmith stub.call(array); 7467754Smsmith long time = System.currentTimeMillis() - start; 7567754Smsmith 7667754Smsmith bsrv.unexport(stub, true); 7767754Smsmith return time; 7867754Smsmith } 7967754Smsmith} 8067754Smsmith