VoyForums
[ Show ]
Support VoyForums
[ Shrink ]
VoyForums Announcement: Programming and providing support for this service has been a labor of love since 1997. We are one of the few services online who values our users' privacy, and have never sold your information. We have even fought hard to defend your privacy in legal cases; however, we've done it with almost no financial support -- paying out of pocket to continue providing the service. Due to the issues imposed on us by advertisers, we also stopped hosting most ads on the forums many years ago. We hope you appreciate our efforts.

Show your support by donating any amount. (Note: We are still technically a for-profit company, so your contribution is not tax-deductible.) PayPal Acct: Feedback:

Donate to VoyForums (PayPal):

Login ] [ Contact Forum Admin ] [ Main index ] [ Post a new message ] [ Search | Check update time ]


[ Next Thread | Previous Thread | Next Message | Previous Message ]

Date Posted: 15:23:17 12/06/01 Thu
Author: Richard In Texas
Subject: Is your code fast enough?

³W«h¡G
1.±N°}¦CA[5000] initialize¡A©ñ¤J0 - 4999¡CµM«á­«½Æ°õ¦æ100000¦¸¡C¤]´N¬O»¡µ{¦¡­n¨â­Ó°j°é¡A¤@­Ó¬O­«½Æªº°j°é¡A¥t¤@­Ó¬Oinitializeªº°j°é¡C
2.±N¦Û¤vªºCµ{¦¡½X¼g¨ì¤U¦CªºªÅ¶¡
3.¥ÎVC++ compile
4.µ{¦¡³Ì«á·|¦L¥Xa[4999]¡A¤ñ¹ï¬Ý¬Ý§Aªºµª®×¬O¤£¬O4999¡A¥H¤Î©Òµo¶Oªº®É¶¡¡C
============================================================

#include <iostream.h>
#include <time.h>
//compare the speed of using assembly and C code
void main()
{
const long num=5000;
const long outloop=100000;
short a[num];
long lTime;


lTime=clock(); //begin
//======================================
//insert your code here





//===================================
lTime=clock()-lTime; //end
cout << "a[4999] = " << a[4999] << endl;
cout << "Your time = " << lTime <<endl;

lTime=clock(); //begin
_asm
{

mov ecx,outloop;
mov ebx,num;
Outloop:
mov edx, ecx;
mov ecx, ebx ;
xor esi, esi ;
xor eax, eax;
DoAgain:
mov word ptr a[esi], ax;
inc eax;
add esi,2;
loop DoAgain
mov ecx, edx;
loop Outloop
}
lTime=clock()-lTime; //end
cout << "a[4999] = " << a[4999] << endl;
cout << "Asm time= " << lTime <<endl;
}



¥Øªº¡G°²¦p±N¨Ó¤u§@®É·Q´£°ª¦Û¤v²£«~ªº®Ä²v¡A¥i¥Î¦¹©Û¡C

[ Next Thread | Previous Thread | Next Message | Previous Message ]

Post a message:
This forum requires an account to post.
[ Create Account ]
[ Login ]
[ Contact Forum Admin ]


Forum timezone: GMT-6
VF Version: 3.00b, ConfDB:
Before posting please read our privacy policy.
VoyForums(tm) is a Free Service from Voyager Info-Systems.
Copyright © 1998-2019 Voyager Info-Systems. All Rights Reserved.