It is currently Sat May 25, 2013 11:45 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: speed up code
PostPosted: Thu Mar 01, 2012 6:46 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Mar 27, 2009 9:41 am
Posts: 333
Location: Athens, Greece
My question may be a little stupid so I apologise from now.
I have the following code:
Code:
Dim temp.b(ArraySize.l)
For i = 1 To 8
   For ii= 1 To ArraySize
      temp(ii) = Random(255)
   Next
   ....
Next

to create an array with random data 8 times. The code is a little slow when ArraySize is a number like 1,000,000.
I know that this is obvious when we call Random() so many times but is there any way to speed up?

_________________
http://kc2000labs.shadowtavern.com/pb/pb_eng.htm


Top
 Profile  
 
 Post subject: Re: speed up code
PostPosted: Thu Mar 01, 2012 6:55 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Dec 23, 2003 3:54 am
Posts: 932
Location: New York
Try this:

Code:
Dim temp.b(ArraySize.l)
For i = 1 To 8
   RandomData( @temp(0), ArraySize )
   ....
Next


You can only use this trick because you random range is 0-255... all 8 bits of every single byte.

If you were using something like temp(ii) = Random(100) then it wouldn't work correctly.


Top
 Profile  
 
 Post subject: Re: speed up code
PostPosted: Thu Mar 01, 2012 7:32 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Mar 27, 2009 9:41 am
Posts: 333
Location: Athens, Greece
With your code, if ArraySize is 30,000,000 then the time needed to operate is not more than 330 milliseconds.

That was what I needed!! Thanx a lot!!

_________________
http://kc2000labs.shadowtavern.com/pb/pb_eng.htm


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye