smohamed
smohamed

Reputation: 3314

will obfuscation make my program more optimized

I am implementing a DES Encryption algorithm using C++, I benchmark it on a very large document(1.1MB) plaint text.

I have now reached about 1.1 sec on encryption, I need to squeeze off more performance out of it.

I was thinking of obfuscation, will that help in optimizing my code?

Upvotes: 1

Views: 147

Answers (3)

Blender
Blender

Reputation: 298166

I think optimizing your code is the best way to optimize it:

  • Fix redundant code
  • Rethink the logic
  • Remove unused or trivial variables
  • Store commonly used values in variables to reduce redundant computation

Obfuscation makes code harder to read by:

  • Replacing variable names with underscores or single letters (compilers don't use variable names)
  • Removing whitespace to create a neutron star of unreadable text (compilers do this internally)
  • Removing comments (compilers don't read comments)
  • Sometimes adding useless code to further hinder readability (making your program run slower)

Upvotes: 8

Luchian Grigore
Luchian Grigore

Reputation: 258598

C++ compilers nowadays are really REALLY smart. Major optimizations come at a macroscopic level. Even Blender's example, removing unused variables, is not needed, since the optimizer will remove them anyway.

Obfuscation doesn't make your code smarter, it doesn't change algorithms, it doesn't introduce dynamic programming, or anything of the sort.

I don't see why you would want that though. With compiled languages, you don't have to ship the source code, you can, if needed, ship headers and libraries, but those don't give away implementation details.

Upvotes: 0

Doc Brown
Doc Brown

Reputation: 20044

Well, you did not write what kind of obfuscation you have in mind (on a source code level?), but generally: no, it won't. In a language like Javascript (or very old interpreted basic dialects), sometimes obfuscation and optimization go hand-in-hand (shorten variable names, deleting unnecessary whitespace/indentation etc.), but not in a compiled language like C++.

Of course, sometimes some kind of misguided optimization will lead to obfuscated code, but that is a different thing.

Upvotes: 2

Related Questions