|
-
Dec 12th, 2001, 07:05 PM
#1
Thread Starter
PowerPoster
does my computer suck?
i made a program, see thread "This code is pissing me off" that times how long it takes a computer to count to 1 billion. I ran it several times under different conditions, and the average was about 18 seconds. This seems very long for me, it seems that it should only take a few seconds. Any ideas?
my computer is a 450mhz PIII.
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
-
Dec 12th, 2001, 09:12 PM
#2
transcendental analytic
I had to remove the optimations for msvc to get that i wanted to actually loop 
Code:
; 234 : for(int c=0;c<1000000000;++c);
mov DWORD PTR _c$[ebp], 0
jmp SHORT $L8938
$L8939:
mov eax, DWORD PTR _c$[ebp]
add eax, 1
mov DWORD PTR _c$[ebp], eax
$L8938:
cmp DWORD PTR _c$[ebp], 1000000000 ; 3b9aca00H
jge SHORT $L8940
jmp SHORT $L8939
Anyways it seems to take 6 instructions per loop i have a 1.33Ghz Thunderbird (running at 1.00Ghz currently) and it takes about 6 seconds. That makes sense: 1Billion*6~6G Cpu cycles.
This loop seems to be incredibly stupid anyway, I would use a register, and cut down the amount of instructions to 3. Probably something to do with the optimations.
Post your assembler listings and we'll see what's taking so long. I guess you have 8 cpu cycles (0.45*18=8)
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Dec 12th, 2001, 09:35 PM
#3
Fanatic Member
Re: does my computer suck?
Originally posted by sail3005
does my computer suck?
Yes
Alcohol & calculus don't mix.
Never drink & derive.
-
Dec 12th, 2001, 10:17 PM
#4
A billion is a pretty big number (ever counted to a thousand?). You might try making the loop counter "register" to force it into a register.
Z.
-
Dec 12th, 2001, 10:26 PM
#5
transcendental analytic
Originally posted by Zaei
A billion is a pretty big number (ever counted to a thousand?). You might try making the loop counter "register" to force it into a register.
Z.
MSVC ignores that pretty much (ask parksie )
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Dec 13th, 2001, 06:55 AM
#6
Now that sucks, to borrow parlance. This is a 'feature' that makes me mad.
Register absolutely does not work for MSVC++. The docset says it is completely ignored. Like we can't figure out how to optimize code. If something becomes 'register' it has nothing to do with whether you declare it that way or not. The compiler is smrter than us, just ask Kedaman
-
Dec 13th, 2001, 07:49 AM
#7
Indeed that does suck. Well, that is why we have inline assembly.
From: MSDN
The 32-bit compiler does not honor user requests for register variables.
Samurai Zaei says: "What? You dare to not honor my request!? Prepare for death!"
Z.
-
Dec 13th, 2001, 07:56 AM
#8
transcendental analytic
Originally posted by Zaei
Indeed that does suck. Well, that is why we have inline assembly.
Samurai Zaei says: "What? You dare to not honor my request!? Prepare for death!"
Z.
Problem is inline assembly and optimation does not work together, once you put something in asm everything the optimizer works so hard for to inline will be wasted. So inline asm is only good when you have something specific, so it's very uncomfortable to have around in the lower layers.
The compiler usually thinks it's smarter, but when you've finally finished your expression templates you'll notice what kinda dumbass it really is.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Dec 13th, 2001, 11:19 AM
#9
For a quick by-hand optimization:
Code:
mov eax, 0
$L8939:
inc eax
cmp eax, 1000000000 ; 3b9aca00H
jl SHORT $L8939
You can make this faster with the LOOP instruction, but I don't know how to use it. The worst thing here is the jmp instruction, it flushes the prefetch queue (meaning the next instruction takes 5-7 cycles instead of 1).
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Dec 13th, 2001, 11:32 AM
#10
transcendental analytic
Code:
mov ecx, 1000000000
f:
loop f
That should do it
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Dec 13th, 2001, 08:08 PM
#11
Thread Starter
PowerPoster
Originally posted by kedaman
Post your assembler listings and we'll see what's taking so long. I guess you have 8 cpu cycles (0.45*18=8)
How do i get the ASM code? I wrote it in C++.
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
-
Dec 14th, 2001, 12:54 AM
#12
transcendental analytic
You can select it to list asm code into a file in project>settings>C++>Category>listing files
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|