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

Pages: 1-4041-

Elegance vs. Performance

Name: Anonymous 2011-05-27 4:11

So /prog/, what would you choose between these two snippets of C code...


int *arr[3];
arr[0] = 1;
arr[1] = 2;
arr[2] = 3;


or...


int i;
int *arr[3];
for (i = 0; i < 3; i++)
  arr[i] = i+1;


The second one is more elegant, but requires more operations.

Name: Anonymous 2011-05-27 4:17

>>1 Here.
Fuck, I changed the way I wrote the snippets halfway through. Disregard the '*'s in the declaration of arr.

Name: Anonymous 2011-05-27 4:19

>>1
What you call elegance or what I'd call being a lazy fuck.

Name: Anonymous 2011-05-27 4:20

int arr[] = {1, 2, 3};

Name: >>4 2011-05-27 4:22

Forgot to mention that this is more elegant and has better performance than either solution present in >>1 (unless optimized by a compiler of course).

Name: Anonymous 2011-05-27 4:26

>>2

It's still valid, though most compilers will give you a warning.

Name: Anonymous 2011-05-27 4:28

>>3
Fair enough.

>>4 and >>5
Excellent point, however, consider a situation in which these operations are done using variables and several operations, for instance:


int *someFunc(int someFactor, int *someArr)
{
  for (int i = 0; i < 3; i++)
    someArr[i] *= (someFactor * someFactor) + SOMECONSTANT;
  return someArr;
}

Name: Anonymous 2011-05-27 4:30

>>6

Yes, it's valid, but it's incorrect and you will more then likely get a segmentation fault. You have a pointer to a pointer there, and you later dereference only one pointer when modifying memory.

Name: Anonymous 2011-05-27 4:39

The compiler probably unwinds the loop anyway, so who cares.

Name: Anonymous 2011-05-27 5:19

That's what you need proper macros for. Enjoy your shitty language without proper macros.

Name: Anonymous 2011-05-27 5:53

>>8

We're not accessing the data the pointers are pointing at so I don't really see the issue.

Name: Anonymous 2011-05-27 5:57

>>7

Then you'll obviously write it as a for loop, that way you may easily modify the program to either jump over some parts of the array, increase the iterations and so on.

Name: Anonymous 2011-05-27 7:04

1.
mov edi, [esp]
xor eax, eax
inc eax
stosd
inc eax
stosd
inc eax
stosd

10 bytes

2.
mov edi, [esp]
mov ecx, 3
:derp
xor eax, eax
inc eax
stosd
loop :derp

11 bytes

So hardly a difference for a compiler that can think.

Name: Anonymous 2011-05-27 7:10

>>14
I think you made a mistake. In example too, the label and xor eax,eax need to exchange places, otherwise you're writing only 1's

Name: Anonymous 2011-05-27 7:22

>>14
Recursion on comment considered harmful

Name: Anonymous 2011-05-27 7:26


#include <stdio.h>
#include <string.h>
int main()
 {
  int * arr[3]; int temp = '1'; int index = 0;
  while(index<2)
   {
   memset(arr + index, temp, index)
   }
  exit 0;
 }

Name: Anonymous 2011-05-27 7:29

any decent compiler optimizes this shit anyway

Name: Anonymous 2011-05-27 7:29

-funroll-loops

                  / ̄∧_∧ ̄ ̄ ̄ // ̄\\
           __ ⊂/__(´∀` )__  /_⊃___| |\フ ヽ  CFLAGS JUST KICKED
       ,  ´_  /   / ̄ ̄ __ / ̄ ヽ    __ヽ ̄ ̄ |  IN, YO!
      /∠__/―/-。―/――∠_/__∧  |       | ∧_.| 
      ,========――´=============/⌒ヽ=|.=====| | ヽ ̄〕 
      | _   |GENTOO|    _  ″  |⌒| |/   __ /|  )ノ    vroom
      )_旧_∈≡≡≡≡∋_旧_″_|| ノ丿_ -――┘ 丿      vroom!
       \ \_ノ  ̄ ̄ ̄三三三\ \_ノ    三三三三 
        三三三三三三三三三三三三三三三三三三三三三三三三
           三三三三三三三三三三三三三三三三三三三三三三三
              三三三三三三三三三三三三三三三三三三三三三三三三三三
                      三三三三三三三三三三三三三三三三三三
                            三三三三三三三三三三三

Name: nambla_dot_org_still_owns_you 2011-05-27 12:33

>>1
Uhh....In the first piece of code, you explicitly name the array elements. In the second, the shit is anonymous. The first case is inflexible, whereas the second case allows you to pretty easily...

Oh cripes, you suck. Either ask your college for a refund or go back to playing with your barbie dolls.

Name: Anonymous 2011-05-27 12:36

>>13

You have to clear the direction flag, if not that will result in undefined behavior.

Name: Anonymous 2011-05-27 12:46

>>13
mov dword [arr+0], 1
mov dword [arr+4], 2
mov dword [arr+8], 3

is even less bytes.

Either way,
section .data
arr: dd 1, 2, 3

is better.

Name: nambla_dot_org_still_owns_you 2011-05-27 12:50

>>21
And just for the record, what both of you idiots are babbling about is machine specific shit. The code would bork some ALPHA machines.

Name: Anonymous 2011-05-27 13:01

>>22
I find it improbable that >>1 or >>13 are using anything else than x86 or x86_64. Feel free to prove me wrong though. I'm also sure you'd be able to modify the assembly code to fit your ``non-standard'' architecture if you're using one, the examples listed are minimal. I'd also be hard pressed to say that anyone here didn't know that assembly code was architecture specific, it's practically by definition. The fact that you even bothered to type such an obvious statement indicates that you are unintelligent, yet want others to view to you highly, in which case I must advise you to not take /prog/ this seriously, relax this is just a textboard.

Name: nambla_dot_org 2011-05-27 13:24

>>23
Listen you autistic jew, what you are rattling about is a non portable solution to a piece of portable C code. To put this in terms that you puny mind can understand, the OPs C code would compile and run on a SPARC, ALPHA, and, the x86. Whereas the assembler code wouldn't.

Name: nambla_dot_org_owns_you 2011-05-27 13:26

>>23
There are a couple ways to write x86 assembler you dumbass nigger. I just don't care for your style of assembler.

Name: Anonymous 2011-05-27 13:45

>>24
the OPs C code would compile and run on a SPARC, ALPHA, and, the x86. Whereas the assembler code wouldn't.
Everybody knows that, again, stating the obvious will only make you seem even less intelligent.

We are having the discussion since the optimal C solution has already been posted. Since you are the one lashing out whenever someone doesn't do what you want you are the one that's likely to be autistic. You should be able to abstract the x86 specific examples into more general assembly code, this is the mark of an intelligent person, since you are unable to do so you must be unintelligent, since this infuriates you, you must be socially unintelligent.

>>25
Your opinion is inconsequential, this is fortified by the fact that you are unintelligent. You simply don't matter. You are without value. Nobody cares about your opinion. I'm sure even you will be able to properly interpret one of the sentences above properly, and perhaps realize a thing or two about yourself.

Name: nambla_dot_org_rules_you 2011-05-27 14:19

>>26
"We are having the discussion since the optimal C solution has already been posted."

I can't find anything in the C89, C90, c99 standard that mentions anything about using assembly to produce optimal C code.

"You should be able to abstract the x86 specific examples into more general assembly code"

That was part of the reason why C was invented you fucking retard.

Name: Anonymous 2011-05-27 14:44

>>27
I can't tell if you're trolling or just really stupid.

Name: Anonymous 2011-05-27 15:21

>>28
I'm not the one who doesn't understand C.

Name: Anonymous 2011-05-27 15:34

>>29
In C/C++ you don't understand things. You just get used to them.

Name: Anonymous 2011-05-27 16:01

>>27,29

I must share >>28 sentiment here, the optimal C solution has been posted, and it wasn't the assembly code. Again you're unable to properly generate an abstraction, C can do things processors are unable to do in the same amount of lines (if we count one instruction as one line), the assembly code posted in this thread gives a general idea what processors are able to do, they can move bits between memory and registers. I'm sure the whole point >>13 was making is that the difference is small when compiled to assembly, so the most readable and modifiable solution is the optimal one.

However, you are still stuck at an infantile level of communication, sticking to worthless insults, you also seem to lack basic reading comprehension. You probably have some brain deficiency, or you just lack general intelligence. Either way I'd recommend you think a little more before you post, or perhaps leave this place altogether, you don't seem to be contributing with anything interesting and you're incapable of listening to anyone that is superior to you.

Name: Anonymous 2011-05-27 16:14

C/C++ has undefined behaviour.
Assembly has no.
------------------------------------
Assembly is more portable than C/C++

We can still run old DOS games after all these years! But given their C/C++ sources we won't be able to compile them in modern C/C++ environment. Write assembly, because C/C++ isn't portable.

Name: Anonymous 2011-05-27 17:08

>>32
C/C++ has undefined behaviour.
You made a non-bullshit statement in that post. I assume that was a mistake so I thought I'd like you know.

Name: nambla_dot_org_rules_you 2011-05-27 17:31

>>31
"I must share >>28 sentiment here, the optimal C solution has been posted, and it wasn't the assembly code. Again you're unable to properly generate an abstraction,"

I believe it was Dr. Richtie that said that C was portable assembler. How much more abstraction do you want you fucking idiot?

"the assembly code posted in this thread gives a general idea what processors are able to do, they can move bits between memory and registers. "

C89, C90, and C99 don't make any reference to C being dependent on assembly. Perhaps you should actually read one of the C standards instead of making up your own definition of what C is.

"However, you are still stuck at an infantile level of communication, sticking to worthless insults, you also seem to lack basic reading comprehension. "

You're projecting. I'm not the only trying to include shit that outside the standard definition of C.

"Either way I'd recommend you think a little more before you post,"

This is coming from a person who writes at the 8th grade level.

Name: Anonymous 2011-05-27 17:32

*that is outside the standard definition of C.*

Name: Anonymous 2011-05-27 17:56

>>20
The direction flag is always cleared in any sane ABI.

Name: Anonymous 2011-05-27 17:57

>>34
You should learn to read, write and interpret written English properly. I suggest you return to whatever basic educational facilities that are available to you and retake (I'm presuming you've already taken them, I realize that might not be the case considering your performance so far) the most basic courses in English, then attempt to learn programming, that way you'll be able to have a normal conversation about programming.

Before you do that I see no point in conversing with you, you seem to be very unintelligent and your behavior is infantile, at the very least basic education should make you somewhat acceptable.

This is coming from a person who writes at the 8th grade level.
I'm not the only trying to include shit that outside the standard definition of C
Right, go back to school, kid.

Name: Anonymous 2011-05-27 17:59

>>37
YHBT FAGGOT

Name: Anonymous 2011-05-27 18:10

>>36
You don't know what trash are in the flags before you run the routine. I'd rather risk using one instruction than getting a practically undetectable bug a couple of years from now. Not doing so should be considered really bad practice actually, as your routine working now is up to chance.

Name: Anonymous 2011-05-27 18:13

>>39
autistic faggot detected

Name: nambla_dot_org_rules_you 2011-05-27 20:08

>>37
"Before you do that I see no point in conversing with you, you seem to be very unintelligent and your behavior is infantile, at the very least basic education should make you somewhat acceptable."

You still have yet to cite a passage from C89, C90, or C99 that cites using assembler as part of the C standard.  Do you even know why we have standards? I bet not you faggot? Do you know how your compiler is implemented in relation to these standards? Again, I bet no. I'm willing to bet that you've never even attempted to write an ANSI/ISO C compiler.

Christ you are one stupid sob. Go back to playing with your barbies. I'm sure barbie and ken will believe your made up definition of C.

Name: Anonymous 2011-05-27 21:19

>>21
This could probably be done in 1 or 2 MMX instructions, but I can't be bothered looking them up right now.

Name: Anonymous 2011-05-27 21:39

100% PURE ANAL!

Name: Anonymous 2011-05-27 21:54

100% PURE ANAL TURING!

Name: Anonymous 2011-05-27 22:23

>>41
Again you are poorly regurgitating common knowledge, everyone here knows what the C standard is, nobody will think you are intelligent for knowing what the C standard is.

If you could contain your learning disabilities long enough to read my posts you'd realize that I never once stated that the assembly code was C, I never once stated the optimal C solution was the assembly code and I never once stated that the optimal C solution was written in anything but ANSI C.

The assembly code was a continuation of the debate, if the optimal C solution already has been posted the problem (within the context of C) is solved and therefore not longer interesting. You probably like to jerk over old knowledge as evident by your continued stating of the obvious in this thread and I guess that is how inferior minds work. However we are superior to you and were able to expand on the problem putting it in a greater context (this is an abstraction of the problem, something you seem to struggle with).

Now, I realize that it might be humiliating to be publicly destroyed like this, especially when the person destroying to you is a male that is superior to you in every other aspect of life, including (but not limited to) athletic, academic and romantic accomplishments. However you must not let this affect you that much, even though you are probably devastated at this point rest assured that nobody probably thinks any worse of you, you didn't seem intelligent before this happened.

Judging by the way you interact with others you are probably somewhere around twelve or thirteen years old, that's good though, you have your entire life ahead of you. So go on child, leave the adults alone and play with your toys, as opposed to nursing your arse pain on /prog/.

Name: nambla_dot_org_rules_you 2011-05-27 22:53

>>45
Stop backtracking you fucking retarded nigger.

BTW, the only way that original code could be considered optimial is if the OP had a conforming C compiler with full optimizations enabled.

And now...

" However we are superior to you and were able to expand on the problem putting it in a greater context (this is an abstraction of the problem, something you seem to struggle with)."

Again, for the third time, C can be considered portable assembler. One could view this as an abstraction of assembler. What part of this don't you understand you mental midget?

Maybe this would help with your mental lack of programming skill you fucking bitch. Say you have a piece of ANSI C code. When I compile and run this on the x86, I get an output. When I compile and run this on a SPARC, I get the same output. And when I compile and run this on the ALPHA, I get the same output.

However, in each case, the assembler is different.  Or as you would but it, you are abstracting the problem.

Again, you are a fucking stupid shit.

Name: Anonymous 2011-05-27 22:55

*would put it*

Name: nambla_dot_org 2011-05-27 22:56

And I'm still not convinced that you understand the relationship between your code and something like the C99 standard.

Name: Anonymous 2011-05-27 23:49

>>46-48
Maybe this would help with your mental lack of programming skill you fucking bitch. Say you have a piece of ANSI C code. When I compile and run this on the x86, I get an output. When I compile and run this on a SPARC, I get the same output. And when I compile and run this on the ALPHA, I get the same output.
Thank you captain obvious.

And I'm still not convinced that you understand the relationship between your code and something like the C99 standard.
Believe me when I say that I'm wholly unconcerned with what you believe. Don't you get it? I simply don't care. You don't matter to me, you don't matter to anyone, nobody gives two shits about you.

Or as you would but it
You should relax more, this is just a textboard, your arse pain is showing, you can't even type correctly now, that's even worse than before. Although, perhaps it's normal to lose basic functionality when you're currently in a state of mental devastation after being publicly humiliated and destroyed by me, the superior male, not that you were functioning very well before that.

Name: Anonymous 2011-05-28 2:17

Conversation about C and compiler optimization. Okay, cool.
Go to work.
Come  back from work.
Argument about language definition/semantics.
Come on, /prog/. Really?

Name: Anonymous 2011-05-28 3:03

>>46-48
u buttmad

Name: Anonymous 2011-05-28 3:41

>>49
You should relax more, this is just a textboard, your arse pain is showing, you can't even type correctly now, that's even worse than before. Although, perhaps it's normal to lose basic functionality when you're currently in a state of mental devastation after being publicly humiliated and destroyed by me, the superior male, not that you were functioning very well before that.

Dearest Salutations Bro,

My name is Mugabe Mbogo, cousin of recently deposed Prince Christopher Moot Mpoolo XVI. It is with a hearty and warm smile that I cheerfully inform you that you are posting on what is probably the most technically precise board on all of 4chan, and as such you have lost the argument hard by looking down on standards and declaring that you do not care.

Further, dearest and kind Bro, as you decided to pull out the "superior male" schtick, you will probably never be invited to any parties around here ever again. You should spend a very long time reconsidering your goals in life, as you have just exerted a significant amount of testosterone alienating the only people who are likely to give more than half a fuck.

Sincerely and wishing your family the best health,

Mugabe "Go the fuck back to /g/ you retarded knuckle-dragger" Mbogo.

Name: Anonymous 2011-05-28 4:03

>>52
suck my dick faggot

Name: nambla_dot_org_rules_you 2011-05-28 11:04

>>49
You were, and probably still are, confused about how assembler gets "abstracted".

"Believe me when I say that I'm wholly unconcerned with what you believe. Don't you get it? I simply don't care. You don't matter to me, you don't matter to anyone, nobody gives two shits about you."

Maybe. But unlike you, I actually do this kind of shit for a living.

Name: Anonymous 2011-05-28 11:32

>>54
You get paid to misinterpret arguments and derail threads with your idiocy?

Name: Anonymous 2011-05-28 11:52

>>55
I'm not the one who fucking doesn't understand that C basically abstracts assembler. Want me to cite some of your previous posts that demonstrate this confusion?

You also made *zero* comments about how your shit assembler code was outside the realm of standard C. I'm suspecting you omitted this comment because you've never actually read one of the standards.

Again, you are stupid. Your posts are ambgiuous, and you show zero scholastic aptitude when you do any kind of technical writing.

Again, go back to playing with your barbie dolls and leave the computer programming to the men.

Name: Anonymous 2011-05-28 12:17

>>56
It doesn't though. There are many things you can do in most every assembly language that you can't in C. Freedom of calling convention, code-as-data-as-code, optimisation. It doesn't abstract it, just limit it and make it a bit more human-readable.

Name: Anonymous 2011-05-28 12:18

>>56
Again, your an anus!

Name: Anonymous 2011-05-28 12:20

>>56
C basically abstracts assembler
nope

Want me to cite some of your previous posts
Sure, this should be interesting.  Good luck finding any.

assembler code ... outside the realm of standard C
Right, and my C code is outside the realm of standard Python.  What kind of retard consults the standard of the wrong language and whines that the language in question doesn't conform to it?

Name: Alpha Male !JsUWe2wpCw 2011-05-28 12:43

>>56

Just for your information >>55 isn't the guy you've talking to so far. Just figured I would tell you before you embarrassed yourself even farther, it's quite obvious you blatantly misunderstood a post written in simple English and let your poor social skills take over from there.

I'm going to start posting with this name so you'll know who I am, and in case there is any confusion: I'm the dude who publicly demolished you.

You're not as clever as you think you are by the way, stating the obvious around the office will probably make you feel intelligent but I'm pretty sure your coworkers think of you as a moron. I'm pretty sure they laugh at you when they say something and you start calling them autistic Jews. That's how you come off as by the way, comical, and perhaps a bit tragic, since any short post will lead you to ranting for a couple of posts riddled with spelling mistakes, calling people niggers and telling them to play with barbie dolls while stating the last thing you read about on Wikipedia, all the while confusing yourself on who is who.

Your life must be pretty disappointing, you're not very good at what's supposed to be your job, although I'm certain this is only a short term job, I'd hate to think that your future was in this.

Earlier I advised you to leave /prog/, now I won't though, I'd hate to be deprived of your gay banter, every place needs someone to laugh at. However, before you throw your next fit I am going to recommend that you relax more, perhaps think a little more before you post, make sure you iron out those spelling mistakes, I'm sure you can do it if you really put your mind to it. Keep in mind that nobody here takes you seriously, if you wish to be taken seriously I'd cut down on the autistic Jew remarks, and perhaps attempt to read and think before you post.

Last but not least, you lost the argument, you made a simple mistake, and instead of simply acknowledging that you made a mistake as any adult would do you started raging like a little child, blaming me for your own shortcomings.

Name: Anonymous 2011-05-28 13:06

I would have the compiler place the constants in the initialized data segment.

Name: nambla_dot_org 2011-05-28 15:02

>>59
"Right, and my C code is outside the realm of standard Python.  What kind of retard consults the standard of the wrong language and whines that the language in question doesn't conform to it? "

The original code was in C, not assembler you halfwit. You started to rattle about shit that doesn't fall within the realm of standard C. I just pointed out that your shit assembler code wasn't covered in any of the known C standards. I never once mentioned any kind of assembler standard. You did. I suspect you did this because you are a mental retard.

Again, you are stupid. And again, go back to playing with your barbie dolls. I'm sure barbie will believe your misconceptions about assembler and its relation to C.

Name: Anonymous 2011-05-28 15:05

>>59
Or better yet you fucking mental retard, instead of acting like some jackass bitch in heat when someone calls you out like the dumbass nigger that you are, why don't you instead take the time to learn how to write a C compiler and linker.

I'm pretty sure that this excercise would clear about your gross misconceptions about C, assembler, and how they are related to each other.

Name: Anonymous 2011-05-28 15:05

*would clear up*

Name: Anonymous 2011-05-28 16:04

>>62-64

u mad?

Name: Anonymous 2011-05-28 18:11

The Jews are after me

Name: Anonymous 2011-05-28 18:12

The Jews are after me

Name: Anonymous 2011-05-28 19:11

python: succinct elegance AND blazing performance

u jelly, c fags?

Name: Anonymous 2011-05-29 1:09

>>68
Lisp
FTFY

Name: Anonymous 2011-05-29 1:37

>>68

>Python
>Performance and Elegance

You're just as slow as Ruby, with half the beauty.

Name: Anonymous 2011-05-29 2:34

>>70

Nothing is as slow as ruby, please leave together with your imageboard fail quotes.

Name: Anonymous 2011-05-29 2:42

>>71

Python 3 and Ruby 1.9 are the same speed, more or less.

Name: Anonymous 2011-05-29 3:13

I would probably just implement a buttsort.

Name: Anonymous 2011-05-29 9:22

>>73
same.

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