int testtimes = 10000000; //測試次數,可自行調節看效果
#region 傳統方式反射
console.writeline("一千萬次反射呼叫效能比較");
trywatch.stop();
console.writeline(testtimes.tostring() + " times 傳統invoke方式反射: " + watch.elapsedmilliseconds + "ms");
}catch (system.exception ex)
#endregion
#region 例項化反射
try + " times invoked by instancereflection@1: " + watch.elapsedmilliseconds + "ms");
}catch (system.exception ex)
#endregion
#region 快速反射
trywatch1.stop();
console.writeline(testtimes.tostring() + " times 快速fastinvoke反射: " + watch1.elapsedmilliseconds + "ms");
}catch (system.exception ex)
#endregion
#region 直接呼叫
trywatch2.stop();
console.writeline(testtimes.tostring() + " times 直接new呼叫: " + watch2.elapsedmilliseconds + "ms");
console.read();
}catch (system.exception ex)
#endregion}}
public class person : iperson
}public inte***ce iperson
}using system;
using system.collections.generic;
using system.linq;
using system.text;
using system.reflection.emit;
using system.reflection;
namespace testinvoke
public static fastinvokehandler getmethodinvoker(methodinfo methodinfo)
, methodinfo.declaringtype.module);
ilgenerator il = dynamicmethod.getilgenerator();
parameterinfo ps = methodinfo.getparameters();
type paramtypes = new type[ps.length];
for (int i = 0; i < paramtypes.length; i++)
localbuilder locals = new localbuilder[paramtypes.length];
for (int i = 0; i < paramtypes.length; i++)
for (int i = 0; i < paramtypes.length; i++)
if (!methodinfo.isstatic)
for (int i = 0; i < paramtypes.length; i++)
if (methodinfo.isstatic)
il.emitcall(opcodes.call, methodinfo, null);
else
il.emitcall(opcodes.callvirt, methodinfo, null);
if (methodinfo.returntype == typeof(void))
il.emit(opcodes.ldnull);
else
emitboxifneeded(il, methodinfo.returntype);
for (int i = 0; i < paramtypes.length; i++)
}il.emit(opcodes.ret);
fastinvokehandler invoder = (fastinvokehandler)dynamicmethod.createdelegate(typeof(fastinvokehandler));
return invoder;
}private static void emitcasttoreference(ilgenerator il, system.type type)
else
}private static void emitboxifneeded(ilgenerator il, system.type type)
}private static void emitfastint(ilgenerator il, int value)
if (value > -129 && value < 128)
else}}
}
redis memcache 效能比較
from redis和memcache非常像的,都是key,value的方式,將資料存放記憶體中。最近在學習redis,在網上看了一些這方面的資料,有三種觀點 1,redis讀寫記憶體比memcache快 2,memcache讀寫記憶體比redis快 3,memcache讀寫記憶體比redis快,但...
apache resin ngnix 效能比較
靜態頁面測試,靜態頁面包括css,js,img ab c 20 n 30 併發測試 高數值的也測過,結論一致 resin2.17 平均響應時間為0.521ms nginx 0.7.65 平均響應時間為1.042ms 少許幾次小於1.042 apache2.0 平均響應時間為最低1.042ms 在re...
tomcat效能比較
tomcat的四種基於http協議的connector效能比較 我們姑且把上面四種connector按照順序命名為 nio,http,pool,niop 為了不讓其他因素影響測試結果,我們只對乙個很簡單的jsp頁面進行測試,這個頁面僅僅是輸出乙個hello world。假設位址是 http tomc...