Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Lines of Code and Optimisation

Name: Anonymous 2013-05-25 8:06

Hi, I'm relatively new to programming and I have a question.

Does few LoC == faster? Or is it in the algorithm itself? Is there an instance where more LoC is faster than the shorter one?

Name: Anonymous 2013-05-25 21:38

                                  /\___/ヽ
    (.`ヽ(`> 、ENTERPRISE QUALITY     /''''''   '''''':::::\
     `'<`ゝr'フ\                 +  |(●),   、(●)、.:| +
  ⊂コ二Lフ^´  ノ, /⌒)                 |  ,,,ノ(、_, )ヽ、,, .::::|
  ⊂l二L7_ノ / -ゝ-')´               .+ |   `-=ニ=- ' .::::::| + .
       \_  、__,.イ\           +     \   `ニニ´  .:::/    +
         (T__ノ   Tヽ        , -r'⌒! ̄ `":::7ヽ.`- 、   ./|  .
         ヽ¬.   / ノ`ー-、ヘ<ー1´|  ヽ | :::::::::::::ト、 \ (  ./ヽ
          \l__,./       i l.ヽ! |   .| ::::::::::::::l ヽ   `7ー.、‐'´ |\-、
            レ|        ヽ | { l   l ::::::::::::::::l ヽ  ,ヘ,',',',ヽ  l:::::::::
            ヽl    /   \ ヽ、  / ::::::::::::::::::ヽ ∨ .〉‐〈 ヽノ|::::::::
             ヽニ二..__   `ー=ゝソ :::::::::::::::::::::::ヽ.   l,',',','l   l::::::::
                      ̄ ̄「 ̄,,;::::::::::::::::::::::::::::ヽ.  |,',',',' ! ,'::::::::
                           l ;;;::::::::::::::::::::::::::::::::::ヽ |,',',',','| /::::::::

Name: Anonymous 2013-05-25 21:39

                                 /\___/ヽ
    (.`ヽ(`> 、ENTERPRISE QUALITY     /''''''   '''''':::::\
     `'<`ゝr'フ\                 +  |(●),   、(●)、.:| +
  ⊂コ二Lフ^´  ノ, /⌒)                 |  ,,,ノ(、_, )ヽ、,, .::::|
  ⊂l二L7_ノ / -ゝ-')´               .+ |   `-=ニ=- ' .::::::| + .
       \_  、__,.イ\           +     \   `ニニ´  .:::/    +
         (T__ノ   Tヽ        , -r'⌒! ̄ `":::7ヽ.`- 、   ./|  .
         ヽ¬.   / ノ`ー-、ヘ<ー1´|  ヽ | :::::::::::::ト、 \ (  ./ヽ
          \l__,./       i l.ヽ! |   .| ::::::::::::::l ヽ   `7ー.、‐'´ |\-、
            レ|        ヽ | { l   l ::::::::::::::::l ヽ  ,ヘ,',',',ヽ  l:::::::::
            ヽl    /   \ ヽ、  / ::::::::::::::::::ヽ ∨ .〉‐〈 ヽノ|::::::::
             ヽニ二..__   `ー=ゝソ :::::::::::::::::::::::ヽ.   l,',',','l   l::::::::
                      ̄ ̄「 ̄,,;::::::::::::::::::::::::::::ヽ.  |,',',',' ! ,'::::::::
                           l ;;;::::::::::::::::::::::::::::::::::ヽ |,',',',','| /::::::::

Name: Anonymous 2013-05-25 21:39

>>17

                                  /\___/ヽ
    (.`ヽ(`> 、ENTERPRISE QUALITY     /''''''   '''''':::::\
     `'<`ゝr'フ\                 +  |(●),   、(●)、.:| +
  ⊂コ二Lフ^´  ノ, /⌒)                 |  ,,,ノ(、_, )ヽ、,, .::::|
  ⊂l二L7_ノ / -ゝ-')´               .+ |   `-=ニ=- ' .::::::| + .
       \_  、__,.イ\           +     \   `ニニ´  .:::/    +
         (T__ノ   Tヽ        , -r'⌒! ̄ `":::7ヽ.`- 、   ./|  .
         ヽ¬.   / ノ`ー-、ヘ<ー1´|  ヽ | :::::::::::::ト、 \ (  ./ヽ
          \l__,./       i l.ヽ! |   .| ::::::::::::::l ヽ   `7ー.、‐'´ |\-、
            レ|        ヽ | { l   l ::::::::::::::::l ヽ  ,ヘ,',',',ヽ  l:::::::::
            ヽl    /   \ ヽ、  / ::::::::::::::::::ヽ ∨ .〉‐〈 ヽノ|::::::::
             ヽニ二..__   `ー=ゝソ :::::::::::::::::::::::ヽ.   l,',',','l   l::::::::
                      ̄ ̄「 ̄,,;::::::::::::::::::::::::::::ヽ.  |,',',',' ! ,'::::::::
                           l ;;;::::::::::::::::::::::::::::::::::ヽ |,',',',','| /::::::::

Name: Anonymous 2013-05-25 21:44

                                   /\___/ヽ
    (.`ヽ(`> 、ENTERPRISE QUALITY     /''''''   '''''':::::\
     `'<`ゝr'フ\                 +  |(●),   、(●)、.:| +
  ⊂コ二Lフ^´  ノ, /⌒)                 |  ,,,ノ(、_, )ヽ、,, .::::|
  ⊂l二L7_ノ / -ゝ-')´               .+ |   `-=ニ=- ' .::::::| + .
       \_  、__,.イ\           +     \   `ニニ´  .:::/    +
         (T__ノ   Tヽ        , -r'⌒! ̄ `":::7ヽ.`- 、   ./|  .
         ヽ¬.   / ノ`ー-、ヘ<ー1´|  ヽ | :::::::::::::ト、 \ (  ./ヽ
          \l__,./       i l.ヽ! |   .| ::::::::::::::l ヽ   `7ー.、‐'´ |\-、
            レ|        ヽ | { l   l ::::::::::::::::l ヽ  ,ヘ,',',',ヽ  l:::::::::
            ヽl    /   \ ヽ、  / ::::::::::::::::::ヽ ∨ .〉‐〈 ヽノ|::::::::
             ヽニ二..__   `ー=ゝソ :::::::::::::::::::::::ヽ.   l,',',','l   l::::::::
                      ̄ ̄「 ̄,,;::::::::::::::::::::::::::::ヽ.  |,',',',' ! ,'::::::::
                           l ;;;::::::::::::::::::::::::::::::::::ヽ |,',',',','| /::::::::

Name: Anonymous 2013-05-25 22:03

What are you people doing?

Name: >>19 2013-05-25 22:04

>>21
I was trying to fix >>17-kun's SJIS art, but apparently he fucked up multiple times.

Name: Cudder !MhMRSATORI!fR8duoqGZdD/iE5 2013-05-26 8:00

Extensive loop unrolling is counterproductive on any good architecture, where the hardware will unroll the loop automatically inside the CPU instead of having to waste cycles fetching each instruction over and over again from the massive amount of wasted cache space.

It might look a little faster in microbenchmarks on that piece of code because you've reduced the barely existent branch delay, but in doing so, you've also evicted a bunch of useful code from the cache --- if it's not a microbenchmark --- and  branch overhead is TINY compared to a cache miss. Those idiots who write 4KB memcpy()s have this problem; yes, your code probably is the fastest way to copy a chunk of data around. No, it's not going to make all programs that use it faster, because now the code in the 1/8th of the L1 cache that it evicted is going to need to be read back in.

Name: Anonymous 2013-05-26 22:27

>>23
Post ignored.

Name: Anonymous 2013-05-26 22:44

Does few LoC == faster?

No.

Compare a hash table associative array with a simple key-value pair array.
The hash table will almost always be significantly faster.

Name: Anonymous 2013-05-26 22:46

Optimisation won't matter once we make computers that can work out all algorithms instantaneously

Name: Anonymous 2013-05-27 5:44

>>26
Well when that day arrives, it will be great.
Until then we'll have to optimise though ^^

Name: Anonymous 2013-05-27 6:21

>>23
Cudder, silly fucktard, go write PHP code, because you shouldn't use broken memcpy: http://lwn.net/Articles/414467/

moreover, compilers have "optimize for size" option, so GCC should provide correct version of malloc for correct CPU, you chosen.

Name: Cudder !MhMRSATORI!fR8duoqGZdD/iE5 2013-05-27 7:53

>>28
glibc memcpy is stupidly bloated. rep movs is The One True memcpy(). It's what Linus himself uses. (Read his comments here:
https://bugzilla.redhat.com/show_bug.cgi?id=638477 )

Name: Anonymous 2013-05-27 9:47

>>23
Btw, how do you learn so much about CPUs ? Did you read the entire Intel manual or do you have some books to recommend ?

Name: Anonymous 2013-05-27 10:02

Does few LoC == faster?
No.

Or is it in the algorithm itself?
Kind of.

Is there an instance where more LoC is faster than the shorter one?
I/O buffering for instance.

Name: Anonymous 2013-05-27 10:09

Name: Anonymous 2013-05-27 10:22

>>32

20.3 - The Keyboard DOS Interface
21.3.1 - Printing via DOS
21.3.2 - Printing via BIOS

That is a lot of computer archeology. Can't wait that part with Dinosaur feces.

Name: Anonymous 2013-05-27 10:36

>>33
Still beats programming an 8255 directly.

Name: Cudder !MhMRSATORI!fR8duoqGZdD/iE5 2013-05-28 6:51

Name: Anonymous 2013-05-28 6:55

>>35
cudder, are you married?

pls respond

Name: Anonymous 2013-05-28 7:26

>>36
I doubt Israel allows gay marriages. It is a fucking fundamentalist zionazi shithole.

Name: Anonymous 2013-05-28 20:12

>>31
I/O buffering for instance.
What?

Name: Anonymous 2013-05-28 20:41

>>37
What? No, Jews are the ones who promote feminism, homofaggotry and all that shit.

Name: Anonymous 2013-05-28 20:52

>>39
They promote it for every country that isn't yishrahell, just like with multiculturalism, immigration, and drugs.

Name: Anonymous 2013-05-28 20:56

>>40
But Cudder is Russian. She's a Russian Jew.

Name: Anonymous 2013-05-29 0:23

premature ejaculation is the root of all evil - Donald Knuth

Name: Anonymous 2013-05-29 6:03

>>42
premature ejaculation is the root of all evil - Donald Knuth
I always thought there was something sinister about me.

Name: Cudder !MhMRSATORI!fR8duoqGZdD/iE5 2013-05-29 7:50

Today's "stupid RISC-inspired design decision" is...

Stack frame alignment on Mac OS.
http://blogs.embarcadero.com/abauer/2010/01/14/38904

Data alignment requirements: another one of those profoundly stupid RISC design decisions. Maybe aligned access really was faster back when hardware was still relatively dumb but it doesn't matter a gnat's ass in these days of super-wide datapaths and Intelligent multilevel caching, instead all it does is uselessly consume memory bandwidth.

Scenario 1: processor never supported unaligned accesses but now it does. As a result all existing code would use only aligned accesses, and allowing unaligned accesses gains no benefit from that. Memory bandwidth becoming more important? Too bad, that old code is wasting it!

Scenario 2: processor always supported unaligned accesses, but a little slower, now unaligned accesses get faster. Existing code can never get slower, only faster. Those who used unaligned accesses will see performance improvements, those who didn't won't. Not a problem for memory bandwidth becoming the bottleneck.

http://lemire.me/blog/archives/2012/05/31/data-alignment-for-speed-myth-or-reality/

"It looks like even the data alignment requirements of SSE instructions will be lifted in the future AMD and Intel processors." See where things are headed? Not allowing unaligned accesses in some of the SSE moves was a huge mistake, and they're trying to fix that now, although I don't really think it'll be easily fixable - existing code won't benefit for the reason stated above.

tl;dr: RISC ISAs are held back by restrictive design decisions, CISCs have a lot more flexibility they can optimise on. "Implement a rich ISA and focus on making it faster over time" is clearly the best strategy here, not "make things simple and horrible now and hope we can increase the clock frequency over time"!

>>41
Japanese/Russian mix. NOT Jewish.

Name: Anonymous 2013-05-29 7:55

>>44
Isn't that what a jew would say?

Name: Anonymous 2013-05-29 8:07

>>44
But are you a she?

Name: Anonymous 2013-05-29 8:31

>>44
implying intel would emloy a non-halakha jew
le master ruseman face

Name: Anonymous 2013-05-29 16:28

>>44
Big design up front, that is. Which is partly justified because hardware interfaces are much less flexible than software ones.

However, you say it like people throw away their source code. Even so, compiling x86 to whatever may be difficult, but it isn't impossible. Also, backcompat is very desirable, but at some point you have to start from scratch to be able to evolve. Someone must climb the hills.

Another spine-chilling behaviour is how often people say how much important is to know how computers work to make better and efficient programs. It's funny because this excerpt suggests the other way around: that the second scenario is better and programmers shouldn't care how computers work because the implementation details can be worked out in the long run. So don't blame me for a decision I didn't made.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List