C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old May 25th, 2007, 11:39 AM
raghvendrac raghvendrac is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2007
Posts: 1 raghvendrac User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 m 27 sec
Reputation Power: 0
Exclamation Plz help me to make C code efficient

i am writing code which is already written in MATLAB in my code,,,, goal is to reduce the execution time ,,,,, In code there is a routine generating normal random numbers,,, which involve sqrt, log, sin, cos of floating pt. number,,,, which is taking large time ,,,,,, the same routine in MATLAB taking time 0.68 sec but my C program taking 3.45 sec ,,,,,
plz help me ,,,, by sugesting how can i resolve this problem....

there r 2 ideas in my mind
1. replace that peace code in assembly
2. do operations in binary mode

but i don't know how i can do this,,,,,,
plz help me ,,,,
or suggest me any other idea,,,,,,,,,,,,
thanks,, raghav

Reply With Quote
  #2  
Old May 25th, 2007, 12:47 PM
ahammad ahammad is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2007
Posts: 43 ahammad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 41 m 19 sec
Reputation Power: 2
I'm not sure I understood your question, but basically what you do is you input a number then apply many mathematical operations to it to generate a random number?

In C++, there is a function in the library that does that for you. It is called rand(), and you can modify it to generate a different set of numbers at every execution of the program by using srand().

Reply With Quote
  #3  
Old May 25th, 2007, 01:42 PM
nosale nosale is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2007
Posts: 110 nosale User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 23 m 10 sec
Reputation Power: 2
raghvendrac,

Cannot optimize your code if you do not post it! It shouldnt be necessary to put assembly into your code... I'm not sure why your code is running so slowly, but if you did it properly, it should definitely be running faster than the matlab code. If you want some suggestions right now, you can make luts for sin, cosine and sqrt. Post the recursive function for your pseudo-random number generator, and your code so we can help you more.

Also, I'm guessing you are trying to write your own pseudo-random number generator because you need some specific properties that rand() will not give you (as ahammad suggested).

EZ-E

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Plz help me to make C code efficient


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT