Delphi的: var Form1: TForm1; m,n,t: Dword; implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject); var i,j,k: Dword; begin n:=7; m:=3; j:=3000; t:=timegettime; for i:=0 to j do for k:=0 to j do begin m:=m-timeGetTime(); n:=n+m; m:=m+n; n:=n*m; m:=m*n; end; Caption:=IntToStr(timegettime-t); end;
C#的: namespace WindowsApplication1 { using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.WinForms; using System.Data; /// <summary> /// Summary description for Form1. /// </summary> public class Form1 : System.WinForms.Form { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.Container components; private System.WinForms.Button button1; public uint m, n, t; [sysimport(dll="winmm.dll")] public static extern uint timeGetTime(); public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // } /// <summary> /// Clean up any resources being used. /// </summary> public override void Dispose() { base.Dispose(); components.Dispose(); } /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.components = new System.ComponentModel.Container (); this.button1 = new System.WinForms.Button (); //@this.TrayHeight = 0; //@this.TrayLargeIcon = false; //@this.TrayAutoArrange = true; button1.Location = new System.Drawing.Point (184, 152); button1.Size = new System.Drawing.Size (75, 23); button1.TabIndex = 0; button1.Text = "button1"; button1.Click += new System.EventHandler (this.button1_Click); this.Text = "Form1"; this.AutoScaleBaseSize = new System.Drawing.Size (6, 14); this.Controls.Add (this.button1); } protected void button1_Click (object sender, System.EventArgs e) { uint i,j,k; t=0; m=7; n=3; j=3000; t=timeGetTime();
for (i=0;i<=j;i++) { for (k=0;k<=j;k++) { m-=timeGetTime(); n+=m; m+=n; n*=m; m*=n; } } t=timeGetTime()-t; this.Text=t.ToString(); } /// <summary> /// The main entry point for the application. /// </summary> public static void Main(string[] args) { Application.Run(new Form1()); } } }
VC的: .......... case IDYES: t=0; m=7; n=3; j=3000; t=timeGetTime(); for (i=0;i<=j;i++) { for (k=0;k<=j;k++) { m-=timeGetTime(); n+=m; m+=n; n*=m; m*=n; } } t=timeGetTime()-t; ltoa(t,temp,10); SetWindowText(hWnd,LPCTSTR(temp)); break; ........
BCB的就不用贴了吧。 to jokerman(): 我并不是想说明谁好谁不好,只是学习之前希望尽量多的了解。 没有想掀起编译器论战的意思。刚好机器上装全了几个编译器,比一比,当是 星期天的消遣而已。不管怎么讲,知道比不知道好,你说是不是。 看看for循环是因为有一个高人说VC的for循环优化得没Delphi好,我想自己试试。 结果是:如果循环体内东西很简单则Delphi快点,但一般还是VC快点。都是小小 的差别。
var
Form1: TForm1;
m,n,t: Dword;
implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
var
i,j,k: Dword;
begin
n:=7;
m:=3;
j:=3000;
t:=timegettime;
for i:=0 to j do
for k:=0 to j do
begin
m:=m-timeGetTime();
n:=n+m;
m:=m+n;
n:=n*m;
m:=m*n;
end;
Caption:=IntToStr(timegettime-t);
end;
namespace WindowsApplication1
{
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.WinForms;
using System.Data; /// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.WinForms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components;
private System.WinForms.Button button1; public uint m, n, t;
[sysimport(dll="winmm.dll")]
public static extern uint timeGetTime();
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent(); //
// TODO: Add any constructor code after InitializeComponent call
//
} /// <summary>
/// Clean up any resources being used.
/// </summary>
public override void Dispose()
{
base.Dispose();
components.Dispose();
} /// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container ();
this.button1 = new System.WinForms.Button ();
//@this.TrayHeight = 0;
//@this.TrayLargeIcon = false;
//@this.TrayAutoArrange = true;
button1.Location = new System.Drawing.Point (184, 152);
button1.Size = new System.Drawing.Size (75, 23);
button1.TabIndex = 0;
button1.Text = "button1";
button1.Click += new System.EventHandler (this.button1_Click);
this.Text = "Form1";
this.AutoScaleBaseSize = new System.Drawing.Size (6, 14);
this.Controls.Add (this.button1);
} protected void button1_Click (object sender, System.EventArgs e)
{
uint i,j,k;
t=0;
m=7;
n=3;
j=3000;
t=timeGetTime();
for (i=0;i<=j;i++)
{
for (k=0;k<=j;k++)
{
m-=timeGetTime();
n+=m;
m+=n;
n*=m;
m*=n;
}
}
t=timeGetTime()-t;
this.Text=t.ToString();
} /// <summary>
/// The main entry point for the application.
/// </summary>
public static void Main(string[] args)
{
Application.Run(new Form1());
}
}
}
..........
case IDYES:
t=0;
m=7;
n=3;
j=3000;
t=timeGetTime();
for (i=0;i<=j;i++)
{
for (k=0;k<=j;k++)
{
m-=timeGetTime();
n+=m;
m+=n;
n*=m;
m*=n;
}
}
t=timeGetTime()-t;
ltoa(t,temp,10);
SetWindowText(hWnd,LPCTSTR(temp));
break;
........
to jokerman(): 我并不是想说明谁好谁不好,只是学习之前希望尽量多的了解。
没有想掀起编译器论战的意思。刚好机器上装全了几个编译器,比一比,当是
星期天的消遣而已。不管怎么讲,知道比不知道好,你说是不是。
看看for循环是因为有一个高人说VC的for循环优化得没Delphi好,我想自己试试。
结果是:如果循环体内东西很简单则Delphi快点,但一般还是VC快点。都是小小
的差别。