⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dispatchperformancetestbase.java

📁 java 调用windows的api
💻 JAVA
字号:
/*
 * DispatchPerformanceTestBase.java -
 *
 * This file is part of the Jawin Project: http://jawinproject.sourceforge.net/
 * 
 * Please consult the LICENSE file in the project root directory,
 * or at the project site before using this software.
 */

/* $Id: DispatchPerformanceTestBase.java,v 1.2 2004/07/18 15:12:35 arosii_moa Exp $ */

package org.jawin.perf;

import org.jawin.COMException;
import org.jawin.COMTestBase;
import org.jawin.DispatchPtr;
import org.jawin.Variant;
import org.jawin.win32.COINIT;

/**
 * Test base for performance tests. These can not fail as such, but gives an
 * indication of the performance costs for different calls.
 *
 * @version     $Revision: 1.2 $
 * @author      Morten Andersen, arosii_moa (at) users.sourceforge.net
 */
public abstract class DispatchPerformanceTestBase extends COMTestBase {

	protected DispatchPtr disp;

	/**
	 * should be implemented by subclass to return the DispatchPtr used in the test.
	 */
	protected abstract DispatchPtr initDisp() throws COMException;

	/**
	 * should be implemented by subclass to release the DispatchPtr used in the test.
	 */
	protected abstract void closeDisp(DispatchPtr itf) throws COMException;
	
	/**
	 * should be implemented by subclass and return the thread model for the test.
	 */
	protected abstract COINIT getThreadModel();

	public void testPropShortDispatch() throws COMException {
		for (int i = 0; i < 10000; i++) {
			disp.put("propShort", new Short((short)117));
		}
	}

	public void testPropShortDispatchGet() throws COMException {
		for (int i = 0; i < 10000; i++) {
			short val = ((Short)disp.get("propShort")).shortValue();
		}		
	}
	
	public void testOutIntDispatchMethod() throws COMException {
		Integer in = new Integer(7);
		Integer out = new Integer(0);
		Variant.ByrefHolder outRef = new Variant.ByrefHolder(out);
		
		for (int i = 0; i < 10000; i++) {
			disp.invoke("outInt", in, out);
			int result = ((Integer)outRef.getRef()).intValue();
			outRef.setRef(out);
		}
	}
	
	public void testMultiplySingleIntArrayDispatchMethod() throws COMException {
		int[] in = { 1, 2, 3, 4, 5 };
		Integer multiplier = new Integer(7);
		int[] out = new int[0];
		Variant.ByrefHolder outRef = new Variant.ByrefHolder(out);

		for (int i = 0; i < 10000; i++) {
			disp.invokeN("multiplySingleIntArray", new Object[] { multiplier , in , outRef } );
			int[] result = (int[])outRef.getRef();
			outRef.setRef(out);
		}
	}
	
	public void testMultiplySeveralIntArraysDispatchMethod() throws COMException {
		int[] in = { 1, 2, 3, 4, 5 };
		int[] in2 = { 11 , 12 , 13 , 14 , 15 , 16 , 17 };
		Integer multiplier = new Integer(7);
		int[] out = new int[0];
		int[] out2 = new int[0];
		Variant.ByrefHolder outRef = new Variant.ByrefHolder(out);
		Variant.ByrefHolder outRef2 = new Variant.ByrefHolder(out2);

		for (int i = 0; i < 10000; i++) {
			disp.invokeN("multiplySeveralIntArrays", new Object[] {
				multiplier , in , out , in2 , out2
			} );
			int[] result = (int[])outRef.getRef();
			outRef.setRef(out);
			int[] result2 = (int[])outRef2.getRef();
			outRef2.setRef(out2);
		}
	}

	protected void setUp() throws Exception {
		super.setUp(getThreadModel());
		disp = initDisp();
	}

	protected void tearDown() throws Exception {
		closeDisp(disp);
		super.tearDown();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -