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

📄 funcptrperformancetest.java

📁 java 调用windows的api
💻 JAVA
字号:
/*
 * FuncPtrPerformanceTest.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: FuncPtrPerformanceTest.java,v 1.1 2004/06/14 19:24:56 arosii_moa Exp $ */

package org.jawin.perf;

import java.io.File;
import java.io.IOException;

import org.jawin.COMException;
import org.jawin.FuncPtr;
import org.jawin.ReturnFlags;
import org.jawin.io.LittleEndianOutputStream;
import org.jawin.io.NakedByteStream;

import junit.framework.TestCase;

/**
 * For performance testing of the Win32 DLL entry point code in {@link org.jawin.FuncPtr}.
 * These tests can not fail as such, but gives an indication of the performance
 * costs for different calls.
 *
 * @version     $Revision: 1.1 $
 * @author      Morten Andersen, arosii_moa (at) users.sourceforge.net
 */
public class FuncPtrPerformanceTest extends TestCase {

	private static String testDllDir = System.getProperty("test.dll.dir");
	private static String testDll = testDllDir + File.separator + "CallCOMUnitTestD.DLL";

	/**
	 * testing time for 10.000 function lookups (and closes) of already
	 * loaded DLL.
	 */
	public void testFunctionLookup() throws COMException {
		// to keep the DLL loaded, we keep one funcPtr loaded
		FuncPtr globalFuncPtr = new FuncPtr(testDll, "SendMeATen");
		for (int i = 0; i < 10000; i++) {
			FuncPtr funcPtr = new FuncPtr(testDll, "SendMeATen");
			funcPtr.close();
		}
		globalFuncPtr.close();
	}

	/**
	 * testing time for 1.000 <b>initial</b> function lookups (and closes).
	 * This is pretty slow as Windows has to load and unload the DLL from
	 * the process space.
	 */
	public void testInitialFunctionLookup() throws COMException {
		for (int i = 0; i < 1000; i++) {
			FuncPtr funcPtr = new FuncPtr(testDll, "SendMeATen");
			funcPtr.close();
		}
	}

	/**
	 * testing time for invoking the shortcut method for one integer.
	 * almost to fast to measure - so 1.000.000 invocations
	 */
	public void testIntegerShortcutMethod() throws COMException {
		FuncPtr funcPtr = new FuncPtr(testDll, "SendMeATen");
		for (int i = 0; i < 1000000; i++) {
			funcPtr.invoke_I(10, ReturnFlags.CHECK_FALSE);
		}
		funcPtr.close();
	}

	/**
	 * testing time for the generic invoke with one integer. 
	 * testing 100.000 invocations.
	 * 
	 * Compare with {@link #testIntegerShortcutMethod()}.
	 */
	public void testIntegerGenericMethod() throws COMException, IOException {
		FuncPtr funcPtr = new FuncPtr(testDll, "SendMeATen");
		for (int i = 0; i < 100000; i++) {
			// could be made slightly faster if we reuse the 
			// NakedByteStream
			NakedByteStream nbs = new NakedByteStream();
			LittleEndianOutputStream leos = new LittleEndianOutputStream(nbs);
			leos.writeInt(10);

			funcPtr.invoke("I::", 4, nbs, null, ReturnFlags.CHECK_FALSE);
		}
		funcPtr.close();
	}

}

⌨️ 快捷键说明

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