On Thu, Jan 24, 2019 at 7:01 PM Karthik Krishnaswamy
<karthik.krishnaswam...@gmail.com> 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 <i...@golang.org> wrote:
>>
>> On Thu, Jan 24, 2019 at 6:21 PM Topget <topget1...@gmail.com> 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 golang-nuts+unsubscr...@googlegroups.com.
>> 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 golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to