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 8:24

I just found this new code optimizing algorithm:

(define (optimize S) (strip "\n" S))

Name: Anonymous 2013-05-25 9:13

>>1
Does few LoC == faster?
No. Faster = more specialized = more SLOC.

I.e. FPGA code is fastest, but requires the more SLOC than assembly code, which requires more SLOC than C/C++, which requires more SLOC than languages with garbage collection.

Name: Anonymous 2013-05-25 9:25

Well, in C, you can compare a dumb strlen implementation with one using a Duff's device. The latter will need more LOCs, but should be faster (depending in the compiler).

Name: Anonymous 2013-05-25 10:05

>>4
Is dd really optimizing?

Name: Anonymous 2013-05-25 10:09

no ^^

Name: Anonymous 2013-05-25 10:19

>>5
It's an unrolled loop.

Name: Anonymous 2013-05-25 10:41

It doesn't really matter really because computers run so fast nowadays. Just use whatever algorithm work best for you. Let's say you were to write a FizzBuzz program.

Which is faster? Using array-look up or an if-else clause-terfuck? You can't tell right?

Name: Anonymous 2013-05-25 11:14

Is there an instance where more LoC is faster than the shorter one?
Yes, compare an adder written in C, and an adder using interfaces, abstract methods and tight coupling cloud enabled business logic performance boosting stock market potential customer leverager in Java.

Name: Anonymous 2013-05-25 12:58

>>9
SUCK MY ADDER

Name: Anonymous 2013-05-25 13:05

>>10
SUCK MY DUBS

Name: Anonymous 2013-05-25 13:06

>>11
Reported

Name: Anonymous 2013-05-25 13:14

Name: Anonymous 2013-05-25 13:17

>>9
yes, but java adder has added value.

Name: Anonymous 2013-05-25 13:19

>>13
KEINE THE COW

Name: Anonymous 2013-05-25 13:26

>>15
DON'T MOCK KEINE ASFASDFASDFASDFASDFASDF I FUCKING HATE YOU CRETIN ASDFASDFASDFASDFASDFAKHDSFQILWEUHFIAUHSDFKLJADSHFKLAHDSFASK MEET THE NASTY END OF MY SHOTGUN AND DIE IN A FIRE CRETIN

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.

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