LongArrayCalls.java revision 0:37a05a11f281
11638Srgrimes/*
21638Srgrimes * Copyright 2000 Sun Microsystems, Inc.  All Rights Reserved.
31638Srgrimes * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
41638Srgrimes *
51638Srgrimes * This code is free software; you can redistribute it and/or modify it
61638Srgrimes * under the terms of the GNU General Public License version 2 only, as
71638Srgrimes * published by the Free Software Foundation.
81638Srgrimes *
91638Srgrimes * This code is distributed in the hope that it will be useful, but WITHOUT
101638Srgrimes * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
111638Srgrimes * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12263142Seadler * version 2 for more details (a copy is included in the LICENSE file that
131638Srgrimes * accompanied this code).
141638Srgrimes *
151638Srgrimes * You should have received a copy of the GNU General Public License version
161638Srgrimes * 2 along with this work; if not, write to the Free Software Foundation,
171638Srgrimes * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
181638Srgrimes *
191638Srgrimes * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
201638Srgrimes * CA 95054 USA or visit www.sun.com if you need additional information or
211638Srgrimes * have any questions.
221638Srgrimes */
231638Srgrimes
241638Srgrimes/*
251638Srgrimes *
261638Srgrimes */
271638Srgrimes
281638Srgrimespackage bench.rmi;
2950476Speter
301638Srgrimesimport bench.Benchmark;
311638Srgrimesimport java.rmi.Remote;
321638Srgrimesimport java.rmi.RemoteException;
331638Srgrimesimport java.rmi.server.UnicastRemoteObject;
341638Srgrimes
351638Srgrimes/**
361638Srgrimes * Benchmark for testing speed of calls with long array arguments and
371638Srgrimes * return values.
381638Srgrimes */
391638Srgrimespublic class LongArrayCalls implements Benchmark {
401638Srgrimes
411638Srgrimes    interface Server extends Remote {
421638Srgrimes	public long[] call(long[] a) throws RemoteException;
431638Srgrimes    }
441638Srgrimes
451638Srgrimes    static class ServerImpl extends UnicastRemoteObject implements Server {
461638Srgrimes	public ServerImpl() throws RemoteException {
471638Srgrimes	}
481638Srgrimes
491638Srgrimes	public long[] call(long[] a) throws RemoteException {
501638Srgrimes	    return a;
511638Srgrimes	}
521638Srgrimes    }
531638Srgrimes
541638Srgrimes    static class ServerFactory implements BenchServer.RemoteObjectFactory {
551638Srgrimes	public Remote create() throws RemoteException {
561638Srgrimes	    return new ServerImpl();
571638Srgrimes	}
581638Srgrimes    }
591638Srgrimes
601638Srgrimes    /**
611638Srgrimes     * Issue long array calls.
621638Srgrimes     * Arguments: <array size> <# calls>
631638Srgrimes     */
641638Srgrimes    public long run(String[] args) throws Exception {
651638Srgrimes	int size = Integer.parseInt(args[0]);
661638Srgrimes	int reps = Integer.parseInt(args[1]);
671638Srgrimes	BenchServer bsrv = Main.getBenchServer();
681638Srgrimes	Server stub = (Server) bsrv.create(new ServerFactory());
691638Srgrimes	long[] array = new long[size];
701638Srgrimes
711638Srgrimes	long start = System.currentTimeMillis();
721638Srgrimes	for (int i = 0; i < reps; i++)
731638Srgrimes	    stub.call(array);
741638Srgrimes	long time = System.currentTimeMillis() - start;
751638Srgrimes
761638Srgrimes	bsrv.unexport(stub, true);
771638Srgrimes	return time;
781638Srgrimes    }
791638Srgrimes}
801638Srgrimes
811638Srgrimes