Testi aşağıdaki komut ile yapmıştım. Ama malesef switch case li yapıdan daha hızlı olmadı. Biraz beklentim çok ama şöyle 4-5 ms çıksa baya hızlı olacak. Aynı işlem php de 70ms sürüyor.
module main;
import std.stdio, std.datetime;
enum{
OP_INC = 0,
OP_VAR = 1,
OP_CMP,
OP_JNE,
OP_HLT
}
void main(){
void *pc;
void*[] opcodes;
asm{ call op_inc;};pc += 0x4;opcodes ~= pc;
asm{ call op_var;};pc += 0x4;opcodes ~= pc;
asm{ call op_cmp;};pc += 0x4;opcodes ~= pc;
asm{ call op_jne;};pc += 0x4;opcodes ~= pc;
asm{ call op_hlt;};pc += 0x4;opcodes ~= pc;
int cmp;//karşılaştırma işlemin için
int sayi, sayi_max=1_000_000;
int cur;
auto list = [2,0,3,4];
auto currentTime = Clock.currTime();
goto startlm;
startl:
cur++;
startlm:
pc = opcodes[list[cur]];
asm { call pc;}
goto startl;
return;
/////////////////////////////////////////////////////////7
asm{
call pc;
}
while(1){}
return;
//OPCODES BURAYA
asm{
op_inc:
call adresal;
mov pc[EBP], EAX;
ret;
}
sayi++;
asm{
ret;
op_cmp:
call adresal;
mov pc[EBP], EAX;
ret;
}
cmp = sayi_max - sayi;
asm{
ret;
op_jne:
call adresal;
mov pc[EBP], EAX;
ret;
}
if(cmp != 0) cur = -1;
asm{
ret;
op_var:
call adresal;
mov pc[EBP], EAX;
ret;
}
asm{
ret;
op_hlt:
call adresal;
mov pc[EBP], EAX;
ret;
}
auto currentTime2 = Clock.currTime();
writeln(currentTime2-currentTime);
writeln("kodlar çalışmayı bitirdi");
while(1){}
asm{
ret;
}
//Adres almak için
asm{adresal: pop EBX ; mov EAX,EBX; push EBX; ret;}
return;
}
Php testimi aşağıdaki kodla yaptım. Araya ekstradan microtime dan dönen metini bölmek için kod yazmadım. Hız testinin daha gerçekçi olması için
<?php
$test = microtime();
for($i=0;$i<1000000;$i++){}
$test2 = microtime();
echo $test2-$test;
?>
Ve bu testler esnasında python, php den daha yavaş olduğunu öğrendim. Çok şaşırdım ama sanırım php nin önceki sürümleri çok ağırmış cache özelliği ile sayesinde bu yavaşlığı kapattığını öğrendim. Tabi bu yavaşlık 5-6 sene önceki bir yavaşlık :)
auto c1 = Clock.currTime();
for(int i; i<1_000_000; i++){
}
auto c2 = Clock.currTime();
writeln(c2-c1);
while(1){}
return;
ayrıca D dilinin hızını test ettiğimizde 3ms çıkıyor. Eğer gerçeğe daha yakın bir hız yakalayabilirsem ve parse edilen kodları uygun algoritma ile işlersem optimize kodla mevcut interpreterlardan daha hızlı bir interpreter yapabilirim :)
Zekeriya
--
[ Bu gönderi, http://ddili.org/forum'dan dönüştürülmüştür. ]