Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with priority and speed of pseudo random generator

Status
Not open for further replies.

rpk2006

Technical User
Apr 24, 2002
225
IN
I have written a program to generate Pseudo Random Data, but I am
facing certain problems with the speed of the generation.

The problem I am facing is that if a user enters a number, ex: 1,2
etc., the program generates a pseudo random file of 1,2...MB.

I am using this way:

----------------------
While (Filelen <> 1)
...
...
...
Wend
----------------------

The problem with this loop is that as this loop starts, all other
system activities suffer. Since my program is supposed to run
minimized and in background, I then used API calls to set the priority
of the current thread to minimum. But still until the loop ends,
all the other system activities hang.

What to do?

Secondly, I am using Hash Algorithm to get the message digest of
the pseudo random numbers. This hash value is written in a file.
But still the process is slow. It writes 1 MB file in about 15-20
minutes. The problem is not with the Hash Algorithm, but with VB.
The C implementations are very fast.
How can I make it fast?

---------------------------------
Securing a computer system has traditionally been a battle of wits: the penetrator tries to find the holes, and the designer tries to close them. � M.Gosser
 
Can you post a sample of your code, so we can give you some advice. Sorry, it's just hard to work out exactly how to speed it up without knowing roughly what is taking the time.

BB
 
There is nothing special.

I digged a lot in this small code, but simply don't know how to speed it up in VB.

-----------------------------------
Private Sub Generate()
Dim MyValue1
Randomize(Timer)
MyValue1 = (10000 + rnd......)
MD = Hash(MyValue1)
Open &quot;file.txt&quot; For Append As #1
Print #1,MD;
Close #1
End Sub

Private Sub Timer1_Timer()
Call Generate
End Sub
----------------------------------


---------------------------------
Securing a computer system has traditionally been a battle of wits: the penetrator tries to find the holes, and the designer tries to close them. � M.Gosser
 
>The problem is not with the Hash Algorithm, but with VB.

Really? You are quite positive that you have done such a perfect translation from C to VB that the issue must be with VB and not with the code you have neded up with?

>The problem is not with the Hash Algorithm
>MD = Hash(MyValue1)

How the heck can we tell (and therefore help)? There is no info here about how you are doing the hash.

In fact the problem is that you have actually given us nothing to go on to analyse the issue and suggest solutions. You need to give us a lot more info here
 
How can I provide the code, if I am using the crypto library HASH class. The library is in DLL form. I call the library as given above.

---------------------------------
Securing a computer system has traditionally been a battle of wits: the penetrator tries to find the holes, and the designer tries to close them. � M.Gosser
 
Well, there should be no practical difference in speed between calling a method or function from a DLL than there is from C...
 
Previously, I was using a Class for MD5 Hash. Then I found the the same Hash in a library. Though performance quite improved, but not as fast as it should be.
I was expecting 1 MB random data written to my file in about 5 minutes as seen in some C programs.

---------------------------------
Securing a computer system has traditionally been a battle of wits: the penetrator tries to find the holes, and the designer tries to close them. � M.Gosser
 

>The problem with this loop is that as this loop starts, all other system activities suffer. Since my program is supposed to run minimized and in background, I then used API calls to set the priority of the current thread to minimum. But still until the loop ends, all the other system activities hang.

leave the priority alone and use doevents with a sleep to slow down the loop if you really have to

>Secondly, I am using Hash Algorithm to get the message digest of the pseudo random numbers. This hash value is written in a file. But still the process is slow. It writes 1 MB file in about 15-20 minutes. The problem is not with the Hash Algorithm, but with VB. The C implementations are very fast. How can I make it fast?

once again it seem like you are complaining about a priority issue and/or it takes longer to write a file over a lan versus to a local hard drive. Also to help with the speed of writing don't write every result. Save x amount of results up in a string then write the string out at once then reset the string (&quot;&quot;) and start over for n amount of results.

...

Then again after rereading this post and seeing your code it is no wonder it is taking so long to write out a file. This is your code...
[tt]
Private Sub Generate()
Dim MyValue1
Randomize(Timer)
MyValue1 = (10000 + rnd......)
MD = Hash(MyValue1)
Open &quot;file.txt&quot; For Append As #1
Print #1,MD;
Close #1
End Sub
[/tt]

move the open and close statements to outside of the loop to gain the performance you are looking for...
[tt]
Private Sub Form_Load()
Open &quot;file.txt&quot; For Append As #1
End Sub

Private Sub Generate()
Dim MyValue1
Randomize(Timer)
MyValue1 = (10000 + rnd......)
MD = Hash(MyValue1)
Print #1,MD;
End Sub

Private Sub Query_Unload(Cancel As Integer, UnloadMode As Integer)
Close #1
End Sub
[/tt]

Granted I do not know what else you have in your program, so the suggestion of form_load and unload are what they are, just suggestions, but to gain the performance you are looking for don't open and close the file everytime you want to write/print to it.

and you really need to read FAQ222-2244 item 15

Good Luck

 

rpk2006, have you read FAQ222-2244 item 15 yet? Have you solved your speed problems?

Good Luck

 
Really very sorry for replying so late. Yes I read point 15 of FAQ222-2224. It is true.

Thanks for your reply. I did the way you suggested, but a mild improvement was seen.

Please try my small routine (as above) by including SHA-256 VB routine available in VB sites.

Anyway thanks for the answer.
 
another simple improvement may be garnered by introducing a doevents line. won't speed up YOUR routine, but at least is will give the system a rest in hte midst of the procedure

MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top