|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
不过你如果学.net的话,你就不要选os了,这课比较底层的。你可以旁听数据库加上软件构件和中间件。(webservices和面向服务的课也应该听一听)
- classStudent{publicstringName{get;set;}}staticdoubleTest(intloop,Studentstu,Func<Student,string>action){varwatch=Stopwatch.StartNew();strings=null;for(vari=0;i<loop;i++)s=action(stu);returnwatch.ElapsedTicks;}staticFunc<Student,string>NativeGetter(){returns=>s.Name;}staticFunc<Student,string>ReflectedGetter(){vartype=typeof(Student);varprop=type.GetProperty("Name");returns=>(string)prop.GetValue(s,null);}staticFunc<Student,string>EmittedGetter(){vardm=newDynamicMethod(name:"EmittedGetter",returnType:typeof(string),parameterTypes:new[]{typeof(Student)},owner:typeof(Student));vartype=typeof(Student);varprop=type.GetMethod("get_Name");varil=dm.GetILGenerator();il.Emit(OpCodes.Ldarg_0);il.Emit(OpCodes.Call,prop);il.Emit(OpCodes.Ret);return(Func<Student,string>)dm.CreateDelegate(typeof(Func<Student,string>));}staticFunc<Student,string>ExpressionGetter(){vartype=typeof(Student);varprop=type.GetMethod("get_Name");ParameterExpressionpa=Expression.Parameter(typeof(Student));Expressionbody=Expression.Call(pa,prop);returnExpression.Lambda<Func<Student,string>>(body,pa).Compile();}staticFunc<Student,string>DynamicGetter(){returns=>{dynamicd=s;returnd.Name;};}[MethodImpl(MethodImplOptions.NoOptimization)]publicstaticvoidRun(){constintloop=5000000;varstu=newStudent{Name="Mike"};vardynamic=Test(loop,stu,DynamicGetter());varexpression=Test(loop,stu,ExpressionGetter());varnative=Test(loop,stu,NativeGetter());varemitted=Test(loop,stu,EmittedGetter());varreflected=Test(loop,stu,ReflectedGetter());Console.WriteLine("native:{0}ndynamic:{1}nemit:{2}nexpression:{3}nreflection:{4}",1,dynamic/native,emitted/native,expression/native,reflected/native);Console.ReadKey();}
复制代码
测试了局
1.当轮回次数对照小的时分,loop=1000
native:1
dynamic:540.444964871194
emit:0.704918032786885
expression:0.224824355971897
reflection:8.37002341920375
2.loop=5000000
native:1
dynamic:4.37328053807767
emit:0.96159470600998
expression:1.00412887828162
reflection:35.909097418095
捆绑编译器。用户不需要受制于厂家,自己就能将程序在新平台上编译运行。除了牛B轰轰的linux,估计也没有系统捆绑c/c++的编译器,而且许多新平台都无法支持复杂的c/c++编译器在上面直接运行。 |
|