Also-rans: the global math/rand functions are thread safe (drawing a random number is protected by a mutex.) If the Java one isn't thread safe, you are comparing apples with oranges.
Try creating a local rand.Rand and see what gives. HTH, -s sent from my droid On Fri, Jan 25, 2019, 07:45 Michael Jones <[email protected] wrote: > Also...pseudo-random number generation is not a specific computation; > there are many ways to do it--some faster some slower, some better some > worse. If you want to time a general poisson disc simulation you would be > better with a grid than calls to rand() because now you are testing the > speed of the chosen random number generator. > > For comparison, your fmt.Println(calPi(100000000)) with the standard > (locking) prng on my notebook: > > 3.14151812 > real 0m5.123s > > versus a one-thread high-quality prng: > > 3.14154348 > real 0m1.395s > > The speedup shows that you are just testing random number generation speed. > > The same computation with a grid of pointCount points... > > root := math.Sqrt(float64(pointCount)) > d := 2 / root > for x := -1.0; x < 1.0; x += d { > for y := -1.0; y < 1.0; y += d { > if x*x+y*y < 1 { > inCircleCount++ > } > } > } > > ...gives: > > 3.14158668 > real 0m0.170s > > So, 5.123 or 1.395 or 0.170 seconds based on how the sample points are > calculated. Performance testing is hard. > > Michael > > On Thu, Jan 24, 2019 at 8:48 PM Ian Lance Taylor <[email protected]> wrote: > >> On Thu, Jan 24, 2019 at 7:01 PM Karthik Krishnaswamy >> <[email protected]> wrote: >> > >> > I am just curious to understand what is the best possible way to >> increase the execution speed of this particular program ? I am still >> learning go though :) >> >> To speed up that particular program, don't use recursive Fibonacci. >> The recursive function that you wrote has complexity O(2 ** N). Write >> a simple loop, complexity O(N). >> >> Ian >> >> >> > On Fri, Jan 25, 2019 at 8:26 AM Ian Lance Taylor <[email protected]> >> wrote: >> >> >> >> On Thu, Jan 24, 2019 at 6:21 PM Topget <[email protected]> wrote: >> >> > >> >> > I have tested several simple functions with Golang and Java. To my >> surprise, Java sometimes is faster than Golang(especially in recursive >> function and some function in standard library such as math/rand.Rand). I >> wonder why. Here is some code I used for test and the result. >> >> >> >> Because goroutines start with a small stack that grows as needed, >> >> deeply recursive functions will tend to have somewhat worse behavior >> >> the first time they are called. >> >> >> >> Ian >> >> >> >> -- >> >> You received this message because you are subscribed to the Google >> Groups "golang-nuts" group. >> >> To unsubscribe from this group and stop receiving emails from it, send >> an email to [email protected]. >> >> For more options, visit https://groups.google.com/d/optout. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "golang-nuts" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> For more options, visit https://groups.google.com/d/optout. >> > > > -- > > *Michael T. [email protected] <[email protected]>* > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
