zyl910

优化技巧、硬件体系、图像处理、图形学、游戏编程、国际化与文本信息处理。

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

博客代码高亮测试

AS3——

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
			   xmlns:s="library://ns.adobe.com/flex/spark" 
			   xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="400" minHeight="300"
			   initialize="initApp()" addedToStage="onAddedToStage()">
	<fx:Declarations>
		<!-- 将非可视元素(例如服务、值对象)放在此处 -->
	</fx:Declarations>
	<fx:Script>
		<![CDATA[
			import away3d.cameras.*;
			import away3d.core.base.*;
			import away3d.events.*;
			import away3d.materials.*;
			import away3d.primitives.*;
			
			import mx.core.UIComponent;
			
			private var m_world:WorldShow = null;
			private var m_worldCtl:UIComponent = null;
			
			private function initApp():void
			{
				doAdd();
			}
			
			private function onAddedToStage():void
			{
				//doAdd();
				if (null!=stage && null!=m_world)
				{
					stage.focus = m_world;
				}
			}
			
			private function doAdd():void
			{
				if (null!=m_world) return;
				m_world = new WorldShow();
				m_world.addEventListener(CameraEvent.CAMERA_UPDATED, onCameraUpdated, false, 0, true);
				m_world.addEventListener(WorldShow.SELECTED_CHANGED, onSelectedChanged, false, 0, true);
				
				//cvsWorld.addChild(pan);
				m_worldCtl = new UIComponent();
				m_worldCtl.addChild(m_world);
				//cvsWorld.addChildAt(m_worldCtl, 0);	// 最底层
				cvsWorld.addElementAt(m_worldCtl, 0);
				
				if (null!=stage)
				{
					stage.focus = m_world;
				}
			}
			
			private function doRemove():void
			{
				if (null==m_world)
					return;
				//
				m_worldCtl.removeChild(m_world);
				//cvsWorld.removeChild(m_worldCtl);
				cvsWorld.removeElement(m_worldCtl);
				m_world = null;
				m_worldCtl = null;
			}
			
			private function doFullScreen():void
			{
				if (stage.displayState == StageDisplayState.NORMAL)
				{
					stage.displayState = StageDisplayState.FULL_SCREEN;
				}
				else
				{
					stage.displayState = StageDisplayState.NORMAL;
				}
			}
			
			private function doSetPos():void
			{
				if (null==m_world) return;
				var nx:Number = Number(txtX.text);
				var ny:Number = Number(txtY.text);
				var nz:Number = Number(txtZ.text);
				var nrx:Number = Number(txtRX.text);
				var nry:Number = Number(txtRY.text);
				var nrz:Number = Number(txtRZ.text);
				
				var camera:Camera3D=m_world.camera;
				camera.rotationX = nrx;
				camera.rotationY = nry;
				camera.rotationZ = nrz;
				camera.position = new Vector3D(nx, ny, nz);
				camera.update();
				//camera.hover(true);
				m_world.notifyCameraUpdate();
			}
			
			// 镜头改变事件
			private function onCameraUpdated(e:CameraEvent):void
			{
				//
				if (null==e)	return;
				var camera:Camera3D = e.camera;
				//trace(camera.x);
				if (null==camera)	return;
				//
				txtX.text = String(camera.x.toFixed(2));
				txtY.text = String(camera.y.toFixed(2));
				txtZ.text = String(camera.z.toFixed(2));
				txtRX.text = String(camera.rotationX.toFixed(2));
				txtRY.text = String(camera.rotationY.toFixed(2));
				txtRZ.text = String(camera.rotationZ.toFixed(2));
				txtfov.text = String(camera.fov.toFixed(2));
				txtfocus.text = String(camera.focus.toFixed(2));
				txtzoom.text = String(camera.zoom.toFixed(2));
			}
			
			private function doSetFov():void
			{
				if (null==m_world) return;
				m_world.camera.fov = Number(txtfov.text);
				m_world.fovDefault = m_world.camera.fov;
				m_world.camera.update();
				m_world.notifyCameraUpdate();
			}
			
			private function doSetFocus():void
			{
				if (null==m_world) return;
				m_world.camera.focus = Number(txtfocus.text);
				var fov:Number = Number(txtfovDef.text);
				if (!isNaN(fov) && fov>0)
				{
					m_world.camera.update();
					m_world.camera.fov = fov;
					m_world.fovDefault = fov;
				}
				else
				{
					m_world.camera.update();
					m_world.fovDefault = m_world.camera.fov;
				}
				m_world.camera.update();
				m_world.notifyCameraUpdate();
			}
			
			private function doSetZoom():void
			{
				if (null==m_world) return;
				m_world.camera.zoom = Number(txtzoom.text);
				m_world.camera.update();
				m_world.fovDefault = m_world.camera.fov;
				m_world.camera.update();
				m_world.notifyCameraUpdate();
			}
			
			private function onSelectedChanged(e:MouseEvent3D):void
			{
				if (null==e)	return;
				if (null==e.object)	return;
				//trace(e.object.name);
				txtObjName.text = e.object.name;
				txtOX.text = String(e.object.x.toFixed(2));
				txtOY.text = String(e.object.y.toFixed(2));
				txtOZ.text = String(e.object.z.toFixed(2));
				txtORX.text = String(e.object.rotationX.toFixed(2));
				txtORY.text = String(e.object.rotationY.toFixed(2));
				txtORZ.text = String(e.object.rotationZ.toFixed(2));
			}
			
			private function doObjSetPos():void
			{
				if (null==m_world) return;
				if (null==m_world.selected)	return;
				var nx:Number = Number(txtOX.text);
				var ny:Number = Number(txtOY.text);
				var nz:Number = Number(txtOZ.text);
				var nrx:Number = Number(txtORX.text);
				var nry:Number = Number(txtORY.text);
				var nrz:Number = Number(txtORZ.text);
				m_world.selected.position = new Vector3D(nx, ny, nz, 1);
			}
			
			protected function chkmoveLockY_clickHandler(event:MouseEvent):void
			{
				// TODO Auto-generated method stub
				m_world.moveLockY = chkmoveLockY.selected;
			}
			
			protected function chklimitCamera_clickHandler(event:MouseEvent):void
			{
				// TODO Auto-generated method stub
				m_world.limitCamera = chklimitCamera.selected;
			}
			
		]]>
	</fx:Script>
	<s:Group id="cvsWorld" x="0" y="0" width="100%" height="100%">
		<s:Panel id="pnlTool" y="10" right="10" width="316" height="200" backgroundAlpha="0.60"
				 title="WorldShow">
			<mx:TabNavigator width="100%" height="100%" creationPolicy="all" backgroundAlpha="0.10">
				<s:NavigatorContent width="100%" height="100%" label="World">
					<s:VGroup x="0" y="0" width="100%" height="100%">
						<s:HGroup width="100%">
							<s:Button id="btnAdd" label="Add" click="doAdd()"/>
							<s:Button id="btnRemove" label="Remove" click="doRemove()"/>
							<s:Button id="btnFullScreen" label="FullScreen" click="doFullScreen()"/>
						</s:HGroup>
						<s:HGroup width="100%">
							<s:CheckBox id="chkmoveLockY" label="moveLockY(Y锁定移动)"
										click="chkmoveLockY_clickHandler(event)" selected="true"/>
							<s:CheckBox id="chklimitCamera" label="limitCamera(限制镜头)"
										click="chklimitCamera_clickHandler(event)" selected="true"/>
						</s:HGroup>
					</s:VGroup>
				</s:NavigatorContent>
				<s:NavigatorContent width="100%" height="100%" label="Camera">
					<s:VGroup x="0" y="0" width="100%" height="100%">
						<s:HGroup width="100%">
							<s:Button id="btnSetPos" label="SetPos" click="doSetPos()"/>
						</s:HGroup>
						<s:HGroup width="100%">
							<s:Label text="x:"/>
							<s:TextInput id="txtX" width="80"/>
							<s:Label text="y:"/>
							<s:TextInput id="txtY" width="80"/>
							<s:Label text="z:"/>
							<s:TextInput id="txtZ" width="80"/>
						</s:HGroup>
						<s:HGroup width="100%">
							<s:Label text="rx:"/>
							<s:TextInput id="txtRX" width="80"/>
							<s:Label text="ry:"/>
							<s:TextInput id="txtRY" width="80"/>
							<s:Label text="rz:"/>
							<s:TextInput id="txtRZ" width="80"/>
						</s:HGroup>
						<s:HGroup width="100%">
							<s:Label text="fov:"/>
							<s:TextInput id="txtfov" width="64"/>
							<s:Label text="focus:"/>
							<s:TextInput id="txtfocus" width="64"/>
							<s:Label text="zoom:"/>
							<s:TextInput id="txtzoom" width="64"/>
						</s:HGroup>
						<s:HGroup width="100%">
							<s:Button id="btnSetFov" label="set fov" click="doSetFov()"/>
							<s:Button id="btnSetFocus" label="set focus" click="doSetFocus()"/>
							<s:TextInput id="txtfovDef" width="80"
										 prompt="fov默认值。当按下“set foucs”时,同时会修改fov。若该文本框为空,就不修改。"/>
							<s:Button id="btnSetZoom" label="set zoom" click="doSetZoom()"/>
						</s:HGroup>
					</s:VGroup>
				</s:NavigatorContent>
				<s:NavigatorContent width="100%" height="100%" label="Object">
					<s:VGroup x="0" y="0" width="100%" height="100%">
						<s:HGroup width="100%">
							<s:Button id="btnObjSetPos" label="SetPos" click="doObjSetPos()"/>
							<s:TextInput id="txtObjName" width="100%"/>
						</s:HGroup>
						<s:HGroup width="100%">
							<s:Label text="x:"/>
							<s:TextInput id="txtOX" width="80"/>
							<s:Label text="y:"/>
							<s:TextInput id="txtOY" width="80"/>
							<s:Label text="z:"/>
							<s:TextInput id="txtOZ" width="80"/>
						</s:HGroup>
						<s:HGroup width="100%">
							<s:Label text="rx:"/>
							<s:TextInput id="txtORX" width="80"/>
							<s:Label text="ry:"/>
							<s:TextInput id="txtORY" width="80"/>
							<s:Label text="rz:"/>
							<s:TextInput id="txtORZ" width="80"/>
						</s:HGroup>
					</s:VGroup>
				</s:NavigatorContent>
			</mx:TabNavigator>
		</s:Panel>
	</s:Group>
</s:Application>


C#——

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

namespace TryPointerCall
{
	/// <summary>
	/// 指针操作接口
	/// </summary>
	public interface IPointerCall
	{
		/// <summary>
		/// 指针操作
		/// </summary>
		/// <param name="p">源指针</param>
		/// <returns>修改后指针</returns>
		unsafe byte* Ptr(byte* p);
	}

#region 非泛型
	/// <summary>
	/// [非泛型] 指针操作基类
	/// </summary>
	public abstract class PointerCall : IPointerCall
	{
		public abstract unsafe byte* Ptr(byte* p);
	}

	/// <summary>
	/// [非泛型] 指针操作派生类: 指针+偏移
	/// </summary>
	public sealed class PointerCallAdd : PointerCall
	{
		/// <summary>
		/// 偏移值
		/// </summary>
		public int Offset = 0;

		public override unsafe byte* Ptr(byte* p)
		{
			return unchecked(p + Offset);
		}
	}

	/// <summary>
	/// [非泛型] 指针操作密封类: 指针+偏移
	/// </summary>
	public sealed unsafe class SldPointerCallAdd : IPointerCall
	{
		/// <summary>
		/// 偏移值
		/// </summary>
		public int Offset = 0;

		public unsafe byte* Ptr(byte* p)
		{
			return unchecked(p + Offset);
		}
	}

	/// <summary>
	/// [非泛型] 指针操作结构体: 指针+偏移
	/// </summary>
	public struct SPointerCallAdd : IPointerCall
	{
		/// <summary>
		/// 偏移值
		/// </summary>
		public int Offset;

		public unsafe byte* Ptr(byte* p)
		{
			return unchecked(p + Offset);
		}
	}

#endregion

#region 泛型
	// !!! C#不支持将整数类型作为泛型约束 !!!
	//public abstract class GenPointerCall<T> : IPointerCall where T: int, long
	//{
	//    public abstract unsafe byte* Ptr(byte* p);

	//    void d()
	//    {
	//    }
	//}

#endregion

#region 全部测试
	/// <summary>
	/// 指针操作的一些常用函数
	/// </summary>
	public static class PointerCallTool
	{
#if DEBUG
		private const int CountLoop = 10000000;	// 循环次数
#else
		private const int CountLoop = 200000000;	// 循环次数
#endif

		/// <summary>
		/// 调用指针操作
		/// </summary>
		/// <typeparam name="T">具有IPointerCall接口的类型。</typeparam>
		/// <param name="ptrcall">调用者</param>
		/// <param name="p">源指针</param>
		/// <returns>修改后指针</returns>
		public static unsafe byte* CallPtr<T>(T ptrcall, byte* p) where T : IPointerCall
		{
			return ptrcall.Ptr(p);
		}
		public static unsafe byte* CallClassPtr<T>(T ptrcall, byte* p) where T : PointerCall
		{
			return ptrcall.Ptr(p);
		}
		public static unsafe byte* CallRefPtr<T>(ref T ptrcall, byte* p) where T : IPointerCall
		{
			return ptrcall.Ptr(p);
		}

		// C#不允许将特定的结构体作为泛型约束。所以对于结构体只能采用上面那个方法,通过IPointerCall接口进行约束,可能会造成性能下降。
		//public static unsafe byte* SCallPtr<T>(T ptrcall, byte* p) where T : SPointerCallAdd
		//{
		//    return ptrcall.Ptr(p);
		//}

		private static int TryIt_Static_Offset;
		private static unsafe byte* TryIt_Static_Ptr(byte* p)
		{
			return unchecked(p + TryIt_Static_Offset);
		}
		/// <summary>
		/// 执行测试 - 静态调用
		/// </summary>
		/// <param name="sOut">文本输出</param>
		private static unsafe void TryIt_Static(StringBuilder sOut, int CountLoop)
		{
			TryIt_Static_Offset = 1;

			// == 性能测试 ==
			byte* p = null;
			Stopwatch sw = new Stopwatch();
			int i;
			unchecked
			{
				#region 测试
				// 硬编码.栈变量
				int iOffset = 1;
				sw.Reset();
				sw.Start();
				for (i = 0; i < CountLoop; ++i)
				{
					p = p + iOffset;
				}
				sw.Stop();
				sOut.AppendLine(string.Format("硬编码.栈变量:\t{0}", sw.ElapsedMilliseconds));

				// 硬编码.栈分配
				int* pOffset = stackalloc int[1];
				pOffset[0] = 1;
				sw.Reset();
				sw.Start();
				for (i = 0; i < CountLoop; ++i)
				{
					p = p + pOffset[0];
				}
				sw.Stop();
				sOut.AppendLine(string.Format("硬编码.栈分配:\t{0}", sw.ElapsedMilliseconds));

				// 硬编码.静态
				sw.Reset();
				sw.Start();
				for (i = 0; i < CountLoop; ++i)
				{
					p = p + TryIt_Static_Offset;
				}
				sw.Stop();
				sOut.AppendLine(string.Format("硬编码.静态:\t{0}", sw.ElapsedMilliseconds));

				// 静态调用
				sw.Reset();
				sw.Start();
				for (i = 0; i < CountLoop; ++i)
				{
					p = TryIt_Static_Ptr(p);
				}
				sw.Stop();
				sOut.AppendLine(string.Format("静态调用:\t{0}", sw.ElapsedMilliseconds));

				#endregion // 测试
			}
		}

		private static long TryIt_Static64_Offset;
		private static unsafe byte* TryIt_Static64_Ptr(byte* p)
		{
			return unchecked(p + TryIt_Static64_Offset);
		}
		/// <summary>
		/// 执行测试 - 静态调用
		/// </summary>
		/// <param name="sOut">文本输出</param>
		private static unsafe void TryIt_Static64(StringBuilder sOut, int CountLoop)
		{
			TryIt_Static64_Offset = 1;

			// == 性能测试 ==
			byte* p = null;
			Stopwatch sw = new Stopwatch();
			int i;
			unchecked
			{
				#region 测试
				// 硬编码.栈变量
				long iOffset = 1;
				sw.Reset();
				sw.Start();
				for (i = 0; i < CountLoop; ++i)
				{
					p = p + iOffset;
				}
				sw.Stop();
				sOut.AppendLine(string.Format("64硬编码.栈变量:\t{0}", sw.ElapsedMilliseconds));

				// 硬编码.栈分配
				long* pOffset = stackalloc long[1];
				pOffset[0] = 1;
				sw.Reset();
				sw.Start();
				for (i = 0; i < CountLoop; ++i)
				{
					p = p + pOffset[0];
				}
				sw.Stop();
				sOut.AppendLine(string.Format("64硬编码.栈分配:\t{0}", sw.ElapsedMilliseconds));

				// 硬编码.静态
				sw.Reset();
				sw.Start();
				for (i = 0; i < CountLoop; ++i)
				{
					p = p + TryIt_Static64_Offset;
				}
				sw.Stop();
				sOut.AppendLine(string.Format("64硬编码.静态:\t{0}", sw.ElapsedMilliseconds));

				// 静态调用
				sw.Reset();
				sw.Start();
				for (i = 0; i < CountLoop; ++i)
				{
					p = TryIt_Static64_Ptr(p);
				}
				sw.Stop();
				sOut.AppendLine(string.Format("64静态调用:\t{0}", sw.ElapsedMilliseconds));

				#endregion // 测试
			}
		}

		/// <summary>
		/// 执行测试 - 非泛型
		/// </summary>
		/// <param name="sOut">文本输出</param>
		private static unsafe void TryIt_NoGen(StringBuilder sOut, int CountLoop)
		{
			// 创建
			PointerCallAdd pca = new PointerCallAdd();
			SldPointerCallAdd dpca = new SldPointerCallAdd();
			SPointerCallAdd spca;
			pca.Offset = 1;
			spca.Offset = 1;

			// 转型
			PointerCall pca_base = pca;
			IPointerCall pca_itf = pca;
			IPointerCall dpca_itf = dpca;
			IPointerCall spca_itf = spca;

			// == 性能测试 ==
			byte* p = null;
			Stopwatch sw = new Stopwatch();
			int i;
			unchecked
			{
				#region 调用
				#region 直接调用
				// 调用派生类
				sw.Reset();
				sw.Start();
				for (i = 0; i < CountLoop; ++i)
				{
					p = pca.Ptr(p);
				}
				sw.Stop();
				sOut.AppendLine(string.Format("调用派生类:\t{0}", sw.ElapsedMilliseconds));

				// 调用密封类
				sw.Reset();
				sw.Start();
				for (i = 0; i < CountLoop; ++i)
				{
					p = dpca.Ptr(p);
				}
				sw.Stop();
				sOut.AppendLine(string.Format("调用密封类:\t{0}", sw.ElapsedMilliseconds));

				// 调用结构体
				sw.Reset();
				sw.Start();
				for (i = 0; i < CountLoop; ++i)
				{
					p = spca.Ptr(p);
				}
				sw.Stop();
				sOut.AppendLine(string.Format("调用结构体:\t{0}", sw.ElapsedMilliseconds));

				#endregion	// 直接调用

				#region 间接调用
				// 调用基类
				sw.Reset();
				sw.Start();
				for (i = 0; i < CountLoop; ++i)
				{
					p = pca_base.Ptr(p);
				}
				sw.Stop();
				sOut.AppendLine(string.Format("调用基类:\t{0}", sw.ElapsedMilliseconds));

				// 调用派生类的接口
				sw.Reset();
				sw.Start();
				for (i = 0; i < CountLoop; ++i)
				{
					p = pca_itf.Ptr(p);
				}
				sw.Stop();
				sOut.AppendLine(string.Format("调用派生类的接口:\t{0}", sw.ElapsedMilliseconds));

				// 调用密封类的接口
				sw.Reset();
				sw.Start();
				for (i = 0; i < CountLoop; ++i)
				{
					p = dpca_itf.Ptr(p);
				}
				sw.Stop();
				sOut.AppendLine(string.Format("调用密封类的接口:\t{0}", sw.ElapsedMilliseconds));

				// 调用结构体的接口
				sw.Reset();
				sw.Start();
				for (i = 0; i < CountLoop; ++i)
				{
					p = spca_itf.Ptr(p);
				}
				sw.Stop();
				sOut.AppendLine(string.Format("调用结构体的接口:\t{0}", sw.ElapsedMilliseconds));

				#endregion	// 间接调用

				#endregion	// 调用

				#region 泛型调用

				#region 泛型基类约束
				// 基类泛型调用派生类
				sw.Reset();
				sw.Start();
				for (i = 0; i < CountLoop; ++i)
				{
					p = CallClassPtr(pca, p);
				}
				sw.Stop();
				sOut.AppendLine(string.Format("基类泛型调用派生类:\t{0}", sw.ElapsedMilliseconds));

				// 基类泛型调用基类
				sw.Reset();
				sw.Start();
				for (i = 0; i < CountLoop; ++i)
				{
					p = CallClassPtr(pca_base, p);
				}
				sw.Stop();
				sOut.AppendLine(string.Format("基类泛型调用基类:\t{0}", sw.ElapsedMilliseconds));

				#endregion // 泛型基类约束

				#region 泛型接口约束 - 直接调用
				// 接口泛型调用派生类
				sw.Reset();
				sw.Start();
				for (i = 0; i < CountLoop; ++i)
				{
					p = CallPtr(pca, p);
				}
				sw.Stop();
				sOut.AppendLine(string.Format("接口泛型调用派生类:\t{0}", sw.ElapsedMilliseconds));

				// 接口泛型调用密封类
				sw.Reset();
				sw.Start();
				for (i = 0; i < CountLoop; ++i)
				{
					p = CallPtr(dpca, p);
				}
				sw.Stop();
				sOut.AppendLine(string.Format("接口泛型调用密封类:\t{0}", sw.ElapsedMilliseconds));

				// 接口泛型调用结构体
				sw.Reset();
				sw.Start();
				for (i = 0; i < CountLoop; ++i)
				{
					p = CallPtr(spca, p);
				}
				sw.Stop();
				sOut.AppendLine(string.Format("接口泛型调用结构体:\t{0}", sw.ElapsedMilliseconds));

				// 接口泛型调用结构体引用
				sw.Reset();
				sw.Start();
				for (i = 0; i < CountLoop; ++i)
				{
					p = CallRefPtr(ref spca, p);
				}
				sw.Stop();
				sOut.AppendLine(string.Format("接口泛型调用结构体引用:\t{0}", sw.ElapsedMilliseconds));

				#endregion	// 直接调用

				#region 间接调用
				// 接口泛型调用基类
				sw.Reset();
				sw.Start();
				for (i = 0; i < CountLoop; ++i)
				{
					p = CallPtr(pca_base, p);
				}
				sw.Stop();
				sOut.AppendLine(string.Format("接口泛型调用基类:\t{0}", sw.ElapsedMilliseconds));

				// 接口泛型调用派生类的接口
				sw.Reset();
				sw.Start();
				for (i = 0; i < CountLoop; ++i)
				{
					p = CallPtr(pca_itf, p);
				}
				sw.Stop();
				sOut.AppendLine(string.Format("接口泛型调用派生类的接口:\t{0}", sw.ElapsedMilliseconds));

				// 接口泛型调用密封类的接口
				sw.Reset();
				sw.Start();
				for (i = 0; i < CountLoop; ++i)
				{
					p = CallPtr(dpca_itf, p);
				}
				sw.Stop();
				sOut.AppendLine(string.Format("接口泛型调用密封类的接口:\t{0}", sw.ElapsedMilliseconds));

				// 接口泛型调用结构体的接口
				sw.Reset();
				sw.Start();
				for (i = 0; i < CountLoop; ++i)
				{
					p = CallPtr(spca_itf, p);
				}
				sw.Stop();
				sOut.AppendLine(string.Format("接口泛型调用结构体的接口:\t{0}", sw.ElapsedMilliseconds));

				#endregion	// 间接调用

				#endregion	// 泛型调用

			}
		}

		/// <summary>
		/// 执行测试 - 泛型
		/// </summary>
		/// <param name="sOut">文本输出</param>
		private static unsafe void TryIt_Gen(StringBuilder sOut, int CountLoop)
		{
			// !!! C#不支持将整数类型作为泛型约束 !!!
		}

		/// <summary>
		/// 执行测试
		/// </summary>
		public static string TryIt()
		{
			StringBuilder sOut = new StringBuilder();
			sOut.AppendLine("== PointerCallTool.TryIt() ==");
			TryIt_Static(sOut, CountLoop);
			TryIt_Static64(sOut, CountLoop);
			TryIt_NoGen(sOut, CountLoop);
			TryIt_Gen(sOut, CountLoop);
			sOut.AppendLine();
			return sOut.ToString();
		}

		/// <summary>
		/// 执行测试 - static
		/// </summary>
		public static string TryItStatic()
		{
			StringBuilder sOut = new StringBuilder();
			int cnt = CountLoop * 10;
			sOut.AppendLine("== PointerCallTool.TryItStatic() ==");
			TryIt_Static(sOut, cnt);
			TryIt_Static64(sOut, cnt);
			sOut.AppendLine();
			return sOut.ToString();
		}
	}
#endregion

}

表格——

环境分类基类派生类密封类结构体结构体的引用
A_2005 直接调用 566 563 161 163  
  接口调用   727 721 1045  
  基类约束泛型调用 902 910      
  接口约束泛型调用   1407 1405 566 480
  接口约束泛型调用接口 1409 1410 1402 1617  
A_2010 直接调用 573 568 162 161  
  接口调用   731 730 1134  
  基类约束泛型调用 785 795      
  接口约束泛型调用   733 808 160 161
  接口约束泛型调用接口 728 727 808 1128  
B_2005 直接调用 668 670 101 116  
  接口调用   767 957 1318  
  基类约束泛型调用 1092 1274      
  接口约束泛型调用   1634 1733 671 700
  接口约束泛型调用接口 1767 1702 1719 1859  
B_2010 直接调用 660 668 103 102  
  接口调用   862 862 1340  
  基类约束泛型调用 676 789      
  接口约束泛型调用   862 956 101 98
  接口约束泛型调用接口 764 966 958 1499  
B64_2005 直接调用 675 676 102 191  
  接口调用   862 870 1344  
  基类约束泛型调用 1346 1256      
  接口约束泛型调用   1633 1743 864 769
  接口约束泛型调用接口 1631 1730 1635 2208  
B64_2010 直接调用 577 580 767 772  
  接口调用   770 771 1253  
  基类约束泛型调用 1250 1287      
  接口约束泛型调用   1633 1638 1250 961
  接口约束泛型调用接口 1635 1634 1637 2117  

 

分类 基类 派生类 密封类 结构体 结构体的引用
直接调用 577 580 767 772
接口调用 770 771 1253
基类约束泛型调用 1250 1287
接口约束泛型调用 1633 1638 1250 961
接口约束泛型调用接口 1635 1634 1637 2117

 

(完)

posted on 2011-09-23 11:02  zyl910  阅读(301)  评论(0编辑  收藏  举报