如何让这段代码更快? [英] How can I make this code to go faster???

查看:67
本文介绍了如何让这段代码更快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我到目前为止的代码,用于生成50.000个随机数。

每次运行时,此代码都会生成相同的序列。但

问题在于它的速度很慢。这需要我的p4 1.6gh几乎10

秒来创建50.000个随机数。这只是一个50k的文字

其他的话。

有人在sciencegroups.com上声称他可以在7秒钟内创造100亿美元的b $ b类似的电脑。

我需要以某种方式加速这段代码。

有人可以看一下并帮我修改它吗?

谢谢很多。

此致,

马丁


以下是代码:


私有Const RAND_SEED As Integer = 123''或任何东西

私有Const MAX_VALUE As Integer = 1000''这假定单个

位数


Private Sub Button1_Click(ByVal sender As System.Object,ByVal
$ b $ as As System.EventArgs)处理Button1.Click

TextBox1.Text =""

Button1.Visible = False

Dim numero As String

Dim r As New Random(RAND_SEED)

for i As Integer = 1到50000

numero + = r.Next(MAX_VALUE).ToString

''StatusBar1.Text = i

Next i

TextBox1.Text = numero

Button1.Visible = True

End Sub


发表于Vianet .com高级Usenet新闻组服务

------------------------------------ ----------------------

**速度**保留**完成**匿名**

------------------------------------------------ ----------
http://www.usenet.com

This is the code I have so far, to generate 50.000 random numbers.
This code will generate the same sequence every time I run it. But the
problem being is that it''s slow. It take on my p4 1.6gh almost 10
seconds to create 50.000 rundom numbers. This is just a 50k text in
other words.
Someone claimed in sciencegroups.com that he could create 100 milion
in 7 seconds on similar computer.
I need to speed this code somehow.
Could someone please look at it and help me to revise it?
Thanks a lot.
Sincerely,
Martin

Here is the code:

Private Const RAND_SEED As Integer = 123 '' Or anything
Private Const MAX_VALUE As Integer = 1000 '' This assumes single
digits

Private Sub Button1_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles Button1.Click
TextBox1.Text = ""
Button1.Visible = False
Dim numero As String
Dim r As New Random(RAND_SEED)
For i As Integer = 1 To 50000
numero += r.Next(MAX_VALUE).ToString
'' StatusBar1.Text = i
Next i
TextBox1.Text = numero
Button1.Visible = True
End Sub

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

推荐答案

好吧,


我会查看stringbuilder类。字符串类不是很优秀的b $ b优化用于追加。这可能会加快您的代码速度。


Chris


" Martin Ho" <毫安****** @ 74tech - 点 - com.no-spam.invalid>在消息中写道

news:40 ********** @ Usenet.com ...
well,

I would look into the stringbuilder class. The string class is not very
optimized for appending. This may speed your code up.

Chris

"Martin Ho" <ma******@74tech-dot-com.no-spam.invalid> wrote in message
news:40**********@Usenet.com...
这是我到目前为止生成的代码,用于生成50.000随机数。
每次运行时,此代码都会生成相同的序列。但问题在于它的速度很慢。它需要我的p4 1.6gh几乎10
秒来创建50.000个随机数。这只是一个50k的文字
换句话说。
有人在sciencegroups.com上声称他可以在7秒钟内在类似的计算机上创造100万美元。
我需要加速这个不知道怎么样。
有人可以看看它并帮我修改它吗?
非常感谢。
真诚的,
Martin

这是代码:

私有Const RAND_SEED As Integer = 123''或任何东西
私有Const MAX_VALUE As Integer = 1000''这假定单个
数字
Private Sub Button1_Click(ByVal sender As System.Object,ByVal
e As System.EventArgs)处理Button1.Click
TextBox1.Text =""
Button1.Visible = False
Dim numero As String
Dim r As New Random(RAND_SEED)
我的整数= 1到50000
numero + = r.Next(MAX_VALUE).ToString
'' StatusBar1.Text = i
接下来我
TextBox1.Text = nu mero
Button1.Visible = True
End Sub

发表于Usenet.com Premium Usenet新闻组服务
------------- ---------------------------------------------
* *速度**保留**完成**匿名**
--------------------------------- -------------------------
http://www.usenet.com
This is the code I have so far, to generate 50.000 random numbers.
This code will generate the same sequence every time I run it. But the
problem being is that it''s slow. It take on my p4 1.6gh almost 10
seconds to create 50.000 rundom numbers. This is just a 50k text in
other words.
Someone claimed in sciencegroups.com that he could create 100 milion
in 7 seconds on similar computer.
I need to speed this code somehow.
Could someone please look at it and help me to revise it?
Thanks a lot.
Sincerely,
Martin

Here is the code:

Private Const RAND_SEED As Integer = 123 '' Or anything
Private Const MAX_VALUE As Integer = 1000 '' This assumes single
digits

Private Sub Button1_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles Button1.Click
TextBox1.Text = ""
Button1.Visible = False
Dim numero As String
Dim r As New Random(RAND_SEED)
For i As Integer = 1 To 50000
numero += r.Next(MAX_VALUE).ToString
'' StatusBar1.Text = i
Next i
TextBox1.Text = numero
Button1.Visible = True
End Sub

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com



好的,你给了我一些关于如何加快进程的想法,我能够将
从5000 /秒推到几乎1.000.000 /秒。

现在我的代码在

这个额外的速度为每秒1.000.000.

这不幸的是仍然比Mersenne Code还少,它能够在7秒内完成$ 000 $ b的100.000.000在奔腾4上(根据科学界人士的说法

团队)

嗯......有没有人可以提出任何其他解决方案来加快速度呢?

小心灵弯曲:)


这是我的代码到目前为止:

Private Const RAND_SEED As Integer = 1234''或其他什么

Private Const MAX_VALUE As Integer = 10''这假定单个

位数

Private Sub Button1_Click(ByVal sender As System.Object,ByVal
$ b $ as As System.EventArgs)处理Button1.Click

TextBox1.Text =""

Button1.Visible = False

Dim numero(10000000)As String

Dim r As New Random(RAND_SEED)

For i As Integer = 1 To 10000000

numero(i) = r.Next(MAX_VALUE).ToString

''StatusBar1.Text = i

Next i


TextBox1.Text = numero(1)+ + +

numero(50000)+" + + numero(10000000)''

证明相同位置的数字是相同的


Button1.Visible = True

结束Sub


发布通过Usenet.com高级Usenet新闻组服务

-------------------- --------------------------------------

** SPEED * *保留**完成**匿名**

-------------------------------- --------------------------
http://www.usenet.com
Ok you gave me some idea how to speed up a process, and I was able to
push it from 5000/second to almost 1.000.000/second.
Now my code generates always the same sequence of random numbers in
this extra speed of 1.000.000 per second.
Which is unfortunatelly still less than Mersenne Code which is able to
do 100.000.000 in 7 seconds on pentium 4 (as per someone from science
groups)
Hm... could anyone come up with any other solution to speed this up?
Little mind bender :)

This is my code so far:
Private Const RAND_SEED As Integer = 1234 '' Or anything
Private Const MAX_VALUE As Integer = 10 '' This assumes single
digits
Private Sub Button1_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles Button1.Click
TextBox1.Text = ""
Button1.Visible = False
Dim numero(10000000) As String
Dim r As New Random(RAND_SEED)
For i As Integer = 1 To 10000000
numero(i) = r.Next(MAX_VALUE).ToString
'' StatusBar1.Text = i
Next i

TextBox1.Text = numero(1) + " + " +
numero(50000) + " + " + numero(10000000) ''
proof that number on same positions are the same

Button1.Visible = True
End Sub

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com


是的,使用非托管代码,在C ++中执行,Web将满示例。


问候 - OHM

Martin Ho写道:
Yes, use unmanaged code, do it in C++, the web will be full of examples.

Regards - OHM
Martin Ho wrote:
好的,你给了我一些关于如何加快进程的想法,我能够将它从5000 /秒推到几乎1.000.000 /秒。
现在我的代码始终生成相同的随机数序列,这个额外的速度为1.000。 000每秒。
这是不幸的直到少于Mersenne Code,它能够在Pentium 4上7秒内完成100.000.000(根据科学团队中的某个人)
嗯...任何人都可以拿出任何其他加快这个问题的解决方案?
小心灵弯曲:)

这是我的代码到目前为止:

Private Const RAND_SEED As Integer = 1234''或任何
Private Const MAX_VALUE As Integer = 10''这假定单个
数字
Private Sub Button1_Click(ByVal sender As System.Object,ByVal
e As System.EventArgs)处理Button1.Click
TextBox1.Text =""
Button1.Visible = False
Dim numero(10000000)As String
Dim r As New Random(RAND_SEED)
对于i as Integer = 1到10000000
numero(i)= r.Next(MAX_VALUE).ToString
''StatusBar1.Text = i
Next i

TextBox1.Text = numero(1)+" + +
numero(50000)+ + + numero(10000000)''
证明相同位置的数字是相同的

Button1.Visible = True
End Sub

发表于Vianet .com高级Usenet新闻组服务
---------------------------------------- ------------------
**速度**保留**完成**匿名**
---------- ------------------------------------------------ <无线电通信/> http://www.usenet.com
Ok you gave me some idea how to speed up a process, and I was able to
push it from 5000/second to almost 1.000.000/second.
Now my code generates always the same sequence of random numbers in
this extra speed of 1.000.000 per second.
Which is unfortunatelly still less than Mersenne Code which is able to
do 100.000.000 in 7 seconds on pentium 4 (as per someone from science
groups)
Hm... could anyone come up with any other solution to speed this up?
Little mind bender :)

This is my code so far:
Private Const RAND_SEED As Integer = 1234 '' Or anything
Private Const MAX_VALUE As Integer = 10 '' This assumes single
digits
Private Sub Button1_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles Button1.Click
TextBox1.Text = ""
Button1.Visible = False
Dim numero(10000000) As String
Dim r As New Random(RAND_SEED)
For i As Integer = 1 To 10000000
numero(i) = r.Next(MAX_VALUE).ToString
'' StatusBar1.Text = i
Next i

TextBox1.Text = numero(1) + " + " +
numero(50000) + " + " + numero(10000000) ''
proof that number on same positions are the same

Button1.Visible = True
End Sub

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com


< br $>
-

最诚挚的问候 - OHM


O_H_M {at} BTInternet {dot} com



--
Best Regards - OHM

O_H_M{at}BTInternet{dot}com


这篇关于如何让这段代码更快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆