我構思的實驗覆蓋到下面幾個我認為是實際項目中比較有代表性的場景
C#部分的代碼
usingSystem;
usingSystem
usingSystem
usingSystem
usingSystem
namespaceTest
{
classTest
{
publicstaticvoidMain(string[]args)
{
Console
Measure(TestDb
Measure(TestList
Measure(TestDict
Measure(TestReflection
}
delegatevoidFuncDelegate();
staticvoidMeasure(FuncDelegatefunc
{
Stopwatchsw=newStopwatch();
sw
func();
sw
Console
}
staticvoidTestDb()
{
using(SqlConnectionconn=newSqlConnection(connStr))
{
conn
SqlCommandcmd=newSqlCommand(sql
SqlDataReaderreader=cmd
while(reader
{
varid=reader[
varcode=reader[
varcargoCode=reader[
varlength=reader[
varwidth=reader[
varheight=reader[
varvol=reader[
varpallet=reader[
}
reader
cmd
conn
}
}
staticvoidTestList()
{
varlist=newList();
constintcount=
for(inti=
for(inti=count
list
}
staticvoidTestDict()
{
vardict=newDictionary();
constintcount=
for(inti=
for(inti=
}
staticvoidTestReflection()
{
AssemblyAssemblyassem=Assembly
Typetype=assem
constintcount=
ConstructorInfoci=type
MethodInfomi=type
for(inti=
objectobj=ci
mi
}
}
conststringconnStr=
conststringsql=
}
}
IronPython部分的代碼:
from__future__importwith_statement
importclr
clr
fromSystem
fromSystem
fromSystem
connStr=
sql=
deftestDb():
withSqlConnection(connStr)asconn:
conn
cmd=SqlCommand(sql
reader=cmd
whilereader
id=reader[
code=reader[
cargoCode=reader[
length=reader[
width=reader[
height=reader[
vol=reader[
pallet=reader[
reader
cmd
conn
deftestList():
lst=[]
count=
foriinxrange(count):
lst
foriinxrange(count
lst
deftestDict():
d={}
count=
foriinxrange(count):
d[
foriinxrange(count):
d
deftestReflection():
clr
fromLibimportTestLib
count=
foriinxrange(count):
obj=TestLib()
obj
defmeasure(fn):
sw=Stopwatch()
sw
fn()
sw
measure(testDb)
measure(testList)
measure(testDict)
measure(testReflection)
運行結果
ASP編程免費提供,內容來源於互聯網,本文歸原作者所有。