i do英文歌:delphi 2007 vs E语言 vs C#运行速度 - Delphi编程

来源:百度文库 编辑:偶看新闻 时间:2024/04/29 03:33:58
delphi 2007 vs E语言 vs C#运行速度
作者:佚名    文章来源:不详    点击数:     更新时间:2007-7-7    

这是用E语言编译的,因为我用的4.05试用版本,没有办法生成EXE文件,只能在E语言环境 下运行
这是E语言的代码:
.版本 2
.程序集 窗口程序集1
.子程序 _按钮1_被单击
.局部变量 时间1, 长整数型
.局部变量 时间2, 长整数型
.局部变量 结果, 整数型
.局部变量 到文本, 整数型
时间1 = 取启动时间 ()
结果 = SumTimes (到数值 (编辑框1.内容))
时间2 = 取启动时间 () - 时间1
编辑框2.内容 = 编辑框2.内容 + 到文本 (结果) + “次累加运算耗费:” + 到文本 (时间2) + “毫秒” + #换行符
.子程序 SumTimes, 长整数型
.参数 timer, 长整数型
.局部变量 结果, 长整数型
结果 = 0
.计次循环首 (timer, )
结果 = 结果 + 1
.计次循环尾 ()
返回 (结果)

这是delphi 2007编译的EXE文件,可以看出差好多了
这是delphi的代码:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
btnAdd: TButton;
Label1: TLabel;
Memo1: TMemo;
procedure btnAddClick(Sender: TObject);
private
{ Private declarations }
function SumTimes(i:Integer):string;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btnAddClick(Sender: TObject);
var
dEnd:real;
dStart:Integer;
str:string;
begin
dStart:=GetTickCount;
str:=SumTimes(strToInt(trim(Edit1.Text)));
dEnd:=GetTickCount-dStart;
memo1.Lines.Add(edit1.Text+'次累加运算耗费:'+floattostr(dEnd)+' 毫秒');
end;
function TForm1.SumTimes(i: Integer):string;
var j,m:integer;
begin
for j := 0 to i - 1 do
begin
m:=m+1;
end;
result:=inttostr(m);
end;
end.

这是我用C# 2005的测试程序,大家可以测试下。
正在装载数据……
下面是C#的代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace cSharpTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//System.DateTime currentTime = new System.DateTime();
int iStart, iEnd;
long st;
iStart = Environment.TickCount;
st = SumTimer(long.Parse(textBox1.Text));
//System.DateTime currentTime1 = new System.DateTime();
iEnd = Environment.TickCount - iStart;
rtb.AppendText(textBox1.Text + "次累加运算耗费:" + iEnd.ToString()+" 毫秒\n");
}
private long SumTimer(long s)
{
long m=0;
for (long i = 1; i <= s; i++)
{
m += 1;
}
return m;
}
}
}
结论:这几个编译器,可以看出效率最高的是直接编译成机器码的delphi,他所编译出的代码大小(418K)。但是C#和E语言都不是直接编译成机器码,所以没有什么可比性,但是E语言的效率比C#高确实有点惊喜!
测试文件:
c#        编译的文件:点次下载 http://dl2.csdn.net/down4/20070628/28050252199.exe
delphi 编译的文件:点次下载  http://http://dl2.csdn.net/down4/20070628/28050658854.exe
本文来源:http://blog.csdn.net/wjames2000/archive/2007/06/28/1669668.aspx