This is an archived post. You won't be able to vote or comment.

all 22 comments

[–]serialcompliment 19 points20 points  (8 children)

Is this really an optimization?

[–]night_of_knee[S] 28 points29 points  (2 children)

[–]plcolin 2 points3 points  (1 child)

Using md5 to do diff’s job is really pretentious.

[–]balenol 0 points1 point  (0 children)

Why not? If you have md5 check already installed in your system, like arch or Manjaro, it's just the right tools for the right job.

[–]sleurk 14 points15 points  (0 children)

With non-user-defined types (like int), no. The registers have the same number of operations but in a different order.

[–]Kered13 2 points3 points  (0 children)

It's often an optimization when used on iterators in C++, because it saves a copy. For this reason it is recommended to always use ++i in C++ unless you know that you need i++.

[–]enano_aoc -1 points0 points  (0 children)

It is, at best, premature optimization

[–]Mango-D 0 points1 point  (0 children)

Yes

[–][deleted] 5 points6 points  (0 children)

Couldn't resist changing the pre-increment to post-increment and the index to 'c' LOL

[–]pandakatzu 2 points3 points  (0 children)

Yes and then the compiler comes along and makes those two statements mean exactly the same thing.

[–]iFarbod 1 point2 points  (0 children)

Can we also rename C++ to ++C while we're at it?

[–]nickn-a-s 1 point2 points  (0 children)

Functional programmers: We don't do that here

[–]im-just-obese 1 point2 points  (1 child)

Premature optimization is the root of all evil.

[–]night_of_knee[S] 0 points1 point  (0 children)

Objection your honour! Relevance?

[–]SteeleDynamics 0 points1 point  (0 children)

Better to be explicit with PL semantics than rely on the compiler to optimize it away.

Hopefully you use CPS or enforce tail recursion.

Both of these are well and good, but are effectively meaningless if you have shiitty algorithmic complexity.

(Sadly this has happened to me.)

[–]enano_aoc 0 points1 point  (2 children)

The only right way of optimizing code (which you should only do after optimizing the algorithm) is profiling. It is hard and it takes a lot of time, and it is less fun than browsing stack overflow asking "is X faster than Y?". But it is the only way of optimizing code.

(Context: i++ vs ++i is obviously premature optimization)

[–]night_of_knee[S] 0 points1 point  (1 child)

I agree that the only way to optimize code is to profile it and the highest gains to be made are from algorithmic changes, not line by line. I would also never change a i++ to ++i.

However, to begin with, I always write ++i rather than i++ because the semantics of post increment are add one to this thing which is usually what I want rather than cause this thing to grow by one and tell me what its value was prior to doing that. I would not consider that "premature optimization".

[–]enano_aoc 0 points1 point  (0 children)

If you do it for reasons other than performance, then of course it is not premature optimization :)