The source content for blog.juliobiason.me
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
4.5 KiB

<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<!-- Enable responsiveness on mobile devices-->
<!-- viewport-fit=cover is to support iPhone X rounded corners and notch in landscape-->
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, viewport-fit=cover">
<title>Julio Biason .Me 4.3</title>
<!-- CSS -->
<link rel="stylesheet" href="https://blog.juliobiason.me/print.css" media="print">
<link rel="stylesheet" href="https://blog.juliobiason.me/poole.css">
<link rel="stylesheet" href="https://blog.juliobiason.me/hyde.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=PT+Sans:400,400italic,700|Abril+Fatface">
</head>
<body class=" ">
<div class="sidebar">
<div class="container sidebar-sticky">
<div class="sidebar-about">
<a href="https:&#x2F;&#x2F;blog.juliobiason.me"><h1>Julio Biason .Me 4.3</h1></a>
<p class="lead">Old school dev living in a 2.0 dev world</p>
</div>
<ul class="sidebar-nav">
<li class="sidebar-nav-item"><a href="&#x2F;">English</a></li>
<li class="sidebar-nav-item"><a href="&#x2F;pt">Português</a></li>
<li class="sidebar-nav-item"><a href="&#x2F;tags">Tags (EN)</a></li>
<li class="sidebar-nav-item"><a href="&#x2F;pt&#x2F;tags">Tags (PT)</a></li>
</ul>
</div>
</div>
<div class="content container">
<div class="post">
<h1 class="post-title">Things I Learnt The Hard Way - Optimization Is For Compilers</h1>
<span class="post-date">
2019-07-15
<a href="https://blog.juliobiason.me/tags/books/">#books</a>
<a href="https://blog.juliobiason.me/tags/things-i-learnt/">#things i learnt</a>
<a href="https://blog.juliobiason.me/tags/optimization/">#optimization</a>
</span>
<p>Let say you need more performance on your application. You may be tempted to
look at your code and think &quot;How can I keep this same logic and still remove a
few cycles, so things seem to go faster?&quot; Well, if you want performance, you
need to change your logic.</p>
<span id="continue-reading"></span>
<p>But before jumping into the code, you may have to check your compiler options.
Maybe you're not generating the optimized version. Maybe there is an option
that you don't use that you can remove from the compilation.</p>
<p>'Cause &quot;optimization&quot; is what a compiler is for. They <em>know</em> where they can
extract most of the underlying architecture, and people have been finding ways
to make the compiled code more performance for decades. Heck, compilers can
even <em>delete</em> parts of your code 'cause they can &quot;see&quot; that a piece of code
will always produce the same result and, thus, isn't necessary and they will
just put the same result where that piece of code was.</p>
<p>What you need to do is to think about a better <em>design</em> for your code, not how
to improve the current code. And trying to trick the compiler by <a href="/books/things-i-learnt/data-types">messing with
the types</a>, although may produce faster
code, will really screw you in the future -- specially cause maintenance and
code understanding will take long and figuring out what went wrong will always
be harder.</p>
<p>Code is written for humans to read. <em>ALWAYS</em>. Optimization is what compilers
do. So find a smarter way to explain what you're trying to do instead of using
shorter words or messing with that your code is saying.</p>
<div>
<div style="float:left">
&lt;&lt; <a href="&#x2F;books&#x2F;things-i-learnt&#x2F;use-utf8">Always Use UTF-8 For Your Strings</a>
</div>
&nbsp;
<div style="float:right">
<a href="&#x2F;books&#x2F;things-i-learnt&#x2F;units">Units Makes Things Clear</a> &gt;&gt;
</div>
</div>
</div>
</div>
</body>
</html>