FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Fatal error!
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Fatal error! [message #180879 is a reply to message #180878] Sun, 24 March 2013 13:05 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 3/24/2013 9:00 AM, Thomas Mlynarczyk wrote:
> gb schrieb:
>
>> Fatal error: Maximum execution time of 60 seconds exceeded in
>> C:\xampp\htdocs\ord.php on line 30
>> Is there a time limits?
>
> Yes there is. But you can change that:
> http://www.php.net/set-time-limit
>
>> This is the script that run locally on xampp:
> [...]
>
> So you are basically creating an array of 100000 elements, each being a
> random number in the range 1 to 100000. That means, statistically, each
> number in the given range would appear once. There's a simpler way to do
> that:
>
> $data = range( 1, 100000 );
> shuffle( $data );
> echo implode( ', ', $data );
>

This would note create an array of random numbers. It will create a
randomized array of numbers - two entirely different things.

In a random array, duplicates are expected to happen. That's the nature
of random numbers.

> Then you want to sort the array. I assume this is some kind of exercise
> and you do this for learning purposes. You have chosen a sorting
> algorithm which is quite time-consuming, i.e. not very efficient, so
> it's no wonder that your script times out, especially when you use such
> a large array.
>

True, quick sort is quite to write - but not so quick in execution.

> You can improve the algorithm a bit: After the first run of the for-loop
> the largest number will have moved to the end of the array, in other
> words, it will already be where it's supposed to be. Therefore, in the
> next round, you don't need to go all the way to the end of the array:
> you can skip the last entry. Likewise, after the second run of the
> for-loop, the second largest number will also be at its final place and
> consequently you can skip the last two elements in the third run. And so
> on. This way, you don't have to pass through the whole array each time
> and your script will run a bit faster. You can achieve this by replacing
> the do-while-loop with another for-loop and you also can get rid of the
> $flag.
>

A minor improvement, but anything helps.

> But there are many other sorting algorithms -- and much more efficient
> ones. It will be instructive to learn about them and try to implement
> them. And then you can compare them to see which is the fastest.
>

Agreed. And learning about different sorting algorithms is a great
learning experience in itself.

> Greetings,
> Thomas
>


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: question about class getters
Next Topic: Seeking help with relative and absolute paths
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 24 06:37:03 GMT 2024

Total time taken to generate the page: 0.04624 seconds