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

Home » Imported messages » comp.lang.php » 500. Turbo Sort
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: 500. Turbo Sort [message #172606 is a reply to message #172599] Tue, 22 February 2011 04:22 Go to previous messageGo to previous message
Peter H. Coffin is currently offline  Peter H. Coffin
Messages: 245
Registered: September 2010
Karma:
Senior Member
On Mon, 21 Feb 2011 18:57:46 -0800 (PST), n00m wrote:
> http://www.spoj.pl/problems/TSORT/
> My php code gets TimeLimitExceeded. Can it be accelerated somehow?
> Just curious. No problem here with C, C++, Pascal etc.
>
> <?php
>
> $a = array_fill(0, 1000001, 0);
>
> fscanf(STDIN, "%d\n", &$n);
>
> for ($i = 0; $i < $n; ++$i) {
> fscanf(STDIN, "%d\n", &$v);
> ++$a[$v];
> }
>
> //sort($a, SORT_NUMERIC);
>
> for ($i = 0; $i < 1000001; ++$i) {
> for ($j = 0; $j < $a[$i]; ++$j) {
> echo $i."\n";
> }
> }
>
> ?>

Is it the sort that's dragging you down, or is it the the multiple
multi-million iteration I/O segments?

------------------
$ cat foo.php
<?php

for ($i = 0; $i < 1000001; ++$i) {
echo "nothing\n";
}

?>
$ time php foo.php >/dev/null
0m2.10s real 0m0.89s user 0m0.73s system
$
------------------

I may not have the fastest machine in the world, but since it takes two
seconds to *throw away* just a million rows of output to something that
has about as little overhead as is possible to have makes me think that
the sort is only a tiny part of your overhead.

--
They got rid of it because they judged it more trouble than it was
worth. (And considering they'd gone to great lengths to minimize its
worth, I suppose they were right.)
-- J. D. Baldwin
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: How to read/to download attachment on an URI?
Next Topic: Proxy to open blocked sites
Goto Forum:
  

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

Current Time: Sat Nov 09 08:48:01 GMT 2024

Total time taken to generate the page: 0.07651 seconds