Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #8815
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: Fatal error! |
| Date | 2013-03-24 09:05 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <kimtj1$eka$1@dont-email.me> (permalink) |
| References | <514ed8b4$0$37122$4fafbaef@reader1.news.tin.it> <kimtdj$a4$1@news.albasani.net> |
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@attglobal.net ==================
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Fatal error! gb <no@yahoo.it> - 2013-03-24 11:43 +0100
Re: Fatal error! Jerry Stuckle <jstucklex@attglobal.net> - 2013-03-24 08:04 -0400
Re: Fatal error! Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2013-03-24 14:00 +0100
Re: Fatal error! Jerry Stuckle <jstucklex@attglobal.net> - 2013-03-24 09:05 -0400
Re: Fatal error! Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2013-03-24 14:34 +0100
csiph-web