Source code For Zawgyi 2008 TO Zawgyi 2009
Python
import sys,re
ENC='utf8'
def zawgyi2new(d):
m=open("zawgyi2new_replace.ini").read().strip().decode('utf8').replace("-",'').replace(' ','').split("\n")
for x in m:
x=x.split("\t")
if x[0]in d:
d=d.replace(x[0],x[1])
return d
if __name__=='__main__':
infile=sys.argv[1]
d=open(infile).read().decode(ENC)
d=zawgyi2new(d)
outfile=infile[:infile.rfind(".")]+"_out.txt"
open(outfile,"wb").write(d.encode(ENC))
PHP
$time_start = microtime(true);
// get contents of a file into a string
$filename = $argv[1];
$handle = fopen($filename, "r");
$d= fread($handle, filesize($filename));
fclose($handle);
$myFile = "zawgyi2new.ini";
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);
$theData=str_replace("-","",$theData);
$m=split("\n",$theData);
foreach ($m as $x)
{
$k=split(" ",$x);
if(strripos($d,$k[0])!=false) $d=str_replace($k[0],$k[1],$d);
}
$fp = fopen("convert_".$argv[1], 'w');
fwrite($fp, $d);
fclose($fp);
$time_end = microtime(true);
$time = $time_end - $time_start;
echo "Total ".$time." seconds";
Python က 1 second နဲ့ 3 MB ရှိတဲ့ file ကိုပြီးတယ်။ PHP ကတော့ 29 seconds လောက်ကြာတယ်။ python က ၁၅ လိုင်း။ php က ၂၃ လိုင်း။ အချိန်တွက်တာ မပါရင်တော့ လိုင်း ၁၉ ပေါ့။ ဒီထက်တိုအောင် ထပ်ရေးမယ်ဆိုရင်တော့ ၁၇ လိုင်းလောက်နဲ့ ပြီးတယ်။ ရှင်းအောင် ရေးထားလို့ပါ။ PHP နဲ့ ၁၅ လိုင်းလောက်နဲ့ရအောင် ရေးလို့ရတယ်။ ဒါပေမယ့် ဖတ်ရတာ ရှုပ်သွားမှာဆိုးလို့။

Leave a Reply