<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Rodrigo Ramirez on Medium]]></title>
        <description><![CDATA[Stories by Rodrigo Ramirez on Medium]]></description>
        <link>https://medium.com/@rodrigo.javier.ramirez?source=rss-4060b04c94e3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*HoOZLsRQmQLmLkp15pFJXw.jpeg</url>
            <title>Stories by Rodrigo Ramirez on Medium</title>
            <link>https://medium.com/@rodrigo.javier.ramirez?source=rss-4060b04c94e3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 04:31:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rodrigo.javier.ramirez/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Are we too many?]]></title>
            <link>https://medium.com/@rodrigo.javier.ramirez/are-we-too-many-9a7dde2d8638?source=rss-4060b04c94e3------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a7dde2d8638</guid>
            <category><![CDATA[overpopulation]]></category>
            <category><![CDATA[population-growth]]></category>
            <category><![CDATA[climate-change]]></category>
            <dc:creator><![CDATA[Rodrigo Ramirez]]></dc:creator>
            <pubDate>Thu, 23 Jan 2020 05:10:59 GMT</pubDate>
            <atom:updated>2020-02-18T22:59:20.757Z</atom:updated>
            <content:encoded><![CDATA[<h4>Reflexions about human population</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V-Hf7cpo7TMM_OD5SGl4XQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@yulokchan?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Joseph Chan</a> on <a href="https://unsplash.com/s/photos/mass-population?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Few people deny anymore that climate change is a reality. What some still pretent to debate is whether climate change is generated by human activity or not.</p><p>The following graph is well known and shows that there is a clear correlation between changes in global temperature and changes in the amount of CO2 in the atmosphere. And it should have been enough to convince the non believers. Because where the CO2 comes from if not human activity?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VBBWwaWQ6B0M8ZjxZTwDSw.png" /><figcaption>Source NOAA</figcaption></figure><p>Well, the non believers still point to reasons like volcanic activity and other natural phenomena. Like there were no volcanos producing CO2 five hundred years ago when the Earth was much cooler.</p><p>Of course scientific work has proven again and again that the amount of CO2 measured in the atmosphere matches really well the CO2 produced by human activities. It has been estimated that 87% of all CO2 in the atmosphere comes from burning fusil fuels: mainly oil, natural gas and coal.</p><p>Regardless negligent governments and special interests, many people are doing their part, educating the public and helping to produce more and more inexpensive clean energy. Others are working on creating more efficient electric cars as well as other means of transportation, while others work on really ingenious ways to trap again CO2 underground.</p><blockquote>I believe we are just buying time. We are not attacking the root of the problem.</blockquote><p>I am a big believer in education, science and technology. I am confident that we will eventually produce enough solutions to stop climate change and perhaps, even to a certain point, revert the damage already done.</p><p>But I believe we are just buying time. We are not attacking the root of the problem, just one of its multiple manifestations.</p><p>Let’s look at this other graph correlating human population and CO2 concentration in the atmosphere. Can we deny there is a correlation? If we accepted long ago from the first graph that climate change is a consequence of CO2 accumulated in the atmosphere, shouldn’t we accept as well that CO2 accumulation is a consequence of human population growth?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D8EWCulffSwpggXZpS1plQ.png" /><figcaption>Sources NOAA and United Nations</figcaption></figure><p>Then, of course we can just skip the CO2 concentration in the above 2 graphs and show a direct correlation between global human population and change in global temperatures.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KXUQYTQIuqyMDFl2E8eCDg.png" /><figcaption>Sources NOAA and United Nations</figcaption></figure><p>The point I want to emphasize is that if we want to have a good chance of succeeding in the long run, we need to look at the root of the problem, and then to where that new problem comes from. It is really naive to think that with a population growing at the pace we humans grow, humanity will have a golden age once we get a better grip on reducing or stopping climate change.</p><p>I believe there is a tipping point that when passed, the effects associated with over population may be obvious and ghastly. If they are not already nasty enough. And just like it is happening today with climate change, technology may help us to accommodate a few more billions of us in our planet Earth. But that will not be enough.</p><p>Think about this, of the planet’s ice free land, 26% is used for livestock grazing and 33% to grow crops to feed livestock. Only 37% of the land is covered by forests and our cities and towns occupy a surprising 1%. Surely, we can be more efficient, but that would probably mean forgetting about what we consider humane and best practices, like giving animals enough space to walk and roam, reduce the use of pesticides and antibiotics, just to mention a few. We could adapt our lifestyle by substituting cattle by poultry or fish, or eventually go vegetarian. But we would be just pushing the turning point a bit more.</p><p>As we grow more food for us, we take more and more land, wiping out other species that whether we want to see it or not, are needed to keep the planet and all in it, including us, healthy and alive. As we use more land to grow food we destroy forests and jungles, reducing our source of oxygen, as well as the means to reduce the levels of CO2 in the atmosphere, and warming the planet in the process.</p><p>But what is the solution then? Science fiction and TV shows talk about colonizing other planets, but is that realistic? If we can not fix Earth, what are the chances that we can really terraform Mars? Or travel to the stars? It seems we are not ready yet.</p><p>I believe the only long term solution is to manage not just to keep the existing population levels, but ideally to start reducing them. Some estimates suggest that the planet can not sustain in the long term a healthy and properly fed population greater than 2 billion people. But we are already 7 billion.</p><p>Our urge to reproduce, just like any other being on Earth, drives our population growth and it has being so far an evolutionary advantage. We are the dominant specie on the planet. But can we just follow our instincts, if Earth does not have enough resources to feed us? It seems to me biology and instincts are not playing to our benefit anymore.</p><p>I have this idea that when hundreds of years in the future humanity looks back, the climate change fight will look like the easy piece in this puzzle, just as today the damage to the ozone layer in the late 20th century is something of the past.</p><p>If fighting climate change seems too hard, consider that the opinions denying it are driven by the fossil fuels industry, powerful but less than 200 years old. Fighting human population growth means dealing with our religious believes and preconceptions, old as culture itself, and responsible in part for what, for good or ill, our society is. Imagine the birth control discussion and similar topics magnified many, many times.</p><p>I think in this case religious believes and teachings are just a consequence of something even deeper is us, not just biological, but social and cultural. Until recently in the US, and in most places it is still the case, we were used to multigenerational family groups. Having many children improves your chances of being taken care of when we are elderly. We may not be aware, but we may fear being hungry at an advanced age.</p><p>So we need to reduce the rate at which we reproduce, and perhaps in order to get there we need to break the very justified fear of not being able to feed and have a decent live when we can not work as hard as we are able in our youth.</p><p>As far as I know all our economic models assume that to be able to support a small retired aged population, a much larger working young population is needed. In the US after WWII, the ratio was 16 working people for every retiring person. Today that ratio changed to be 4 to 1. There should be no wonder that the Social Security administration is in trouble. China government passed in 2013 the “Elderly Rights Law” allowing elder parents to sue their children if they feel neglected, surely not as a way to promote Confucianism, but to force families, not the central government, to support the growing aging population. We are used to think we need to keep growing forever. Clearly we need new economic models to support the world’s new reality. Economic models in which one person’s work is enough to support that person’s retirement. This should be the first step if we are ever going to stop or at least reduce our very accelerated population growth.</p><p>So far I have shown a grim picture, but I think there are reasons to be optimistic. We have a few cases in which populations spontaneously stopped growing and in some cases even reduced their size. European population is showing a negative growth. At the same time the US population continues to grow, but at less than half the rate of the world’s population. What do these samples have in common? I believe the following:</p><ul><li>Higher levels of education and with it prosperity, reducing the fear of aging I was talking about before. If you feel you can support yourself, perhaps you don’t need to produce so many children to feed you in the future.</li><li>Women have gained an equal role in society, both in education as well as the right to go out and work. When we have children, and how many, is more a consensus based on the couple’s need, not a unilateral decision or an almost random event.</li><li>Science and technology have provided us the tools to better control our life and how we live it, including of course when we have children as well as how many.</li></ul><h3>To close</h3><p>Climate change may just be the tip of the iceberg. While science and technology help to alleviate the symptoms, the only long term solution may be to stop the population growth.</p><p>The key to a long term, voluntary population control, may require the poorest societies to have better education and access to technology, as well as promoting women to be equal partners instead of subordinated to men.</p><p>📝 Save this story in <a href="https://usejournal.com/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=society&amp;utm_content=guest_post_read_later_text">Journal</a>.</p><p>🌎 Wake up every Sunday morning to the week’s most noteworthy stories in Society waiting in your inbox. <a href="https://usejournal.com/newsletter/noteworthy-in-society/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=society&amp;utm_content=guest_post_text">Read the Noteworthy in Society newsletter</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9a7dde2d8638" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Coding Interview]]></title>
            <link>https://medium.com/@rodrigo.javier.ramirez/the-coding-interview-853e16fc7953?source=rss-4060b04c94e3------2</link>
            <guid isPermaLink="false">https://medium.com/p/853e16fc7953</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Rodrigo Ramirez]]></dc:creator>
            <pubDate>Sat, 02 Nov 2019 23:31:14 GMT</pubDate>
            <atom:updated>2019-11-02T23:31:14.571Z</atom:updated>
            <content:encoded><![CDATA[<h4>What I believe is important when interviewing software engineers</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oXXvHOcrh3_VcpsivPtFPA.jpeg" /><figcaption>Photo by Kaleidico on Unsplash</figcaption></figure><p>Do you remember the movie Ratatouille? Anyone can cook, right? But not everyone is a chef. I can cook, sort of, but certainly I am not a chef.</p><p>The software industry is not so different. Anyone can code, or so it seems. The question is what to look for when interviewing candidates for software engineer positions?</p><h3>Is it personality?</h3><p>Of course the single most important quality of a person in any job is a positive attitude. It does not matter how smart a person may be. Without a positive, team oriented, and constructive attitude you rather soon will wish that person was not in your team. Volumes could be written about “brilliant” people that companies let go at the first opportunity because of their toxic attitude with their teammates.</p><p>But attitude is not what this article is about, and honestly, experience has taught me that I am not the best at spotting candidates with difficult personalities.</p><h3>What about all these?</h3><p>Some people may say years of experience, exposure to trending, fancy technologies, or even the ability to solve coding problems in our target programming language are the key. In my opinion none of the above are that important.</p><p>Allow me to explain.</p><p>Years of experience may be important, but relevant experience is far more important. A person may have many years of experience without having learned some basic lessons.</p><p>Specific technologies and even programming languages come and go, some ones rather fast. A candidate may be really good with some fancy, trending technology that we are using today. I think this is an important hiring criteria if we are looking for a contractor that will solve a specific problem related to that technology and then go.</p><blockquote>What I am really looking for … is to have a 20 minutes conversation about fundamentals</blockquote><p>Some people fancy asking for riddles about coins, weights, and many others things that supposedly help assessing how the candidate approaches problems. I believe those mind teasers are nice and even fun, but predict nothing; and likely not even the person asking them was able to find the answer until it was explained to him the first time. I have read that some of the larger companies in tech have banned this type of question from their interview process.</p><h3>OK, what about coding?</h3><p>Of course coding it is fundamental. We are looking for a software engineer, whose main task will very likely to write software, isn’t it?</p><p>Yes. When I interview I ask some rather simple coding problems. And yes, I expect simple elegant answers and perhaps the ability to solve the same problem in a different way, specially from a seasoned developer. Let’s say a person coded a solution to a question for which I believe there is an alternative valid solution. Then very likely I would explain the second approach and ask the candidate to code or at least explain how the alternative solution may be approached.</p><p>But … There is always a but … In today’s world I would expect any serious candidate to have solved many programing problems using online tools like leetcode.com or hackerrank.com before coming to an interview. It is said that successful candidates solve at least 150 coding questions before interviewing with Google or Amazon.</p><p>With the above in mind, chances are that any coding problem I ask, or at least a very similar one, has already being solved by the candidate. For me being a good software engineer is not about memorizing the solutions to a bunch of typical problems. Solving many problems is just the beginning of the journey.</p><h3>Then what? Will you finally tell me?</h3><p>OK. Enough teasers... What I am really looking for when I interview a candidate for a software engineer position is to have a 20 minutes conversation about fundamentals. For me the difference between a programmer and a software engineer, read «cook» vs «chef», is the understanding and ability to reason about fundamentals.</p><p>I am looking for a candidate that can thrive, and for many years grow side by side with the team. A person that can challenge any other in the team and together analyze many aspects of a problem before committing to a solution. Such a person needs to be far more than a coder.</p><p>Back to the coding problem, in addition to perhaps be able to provide more than one solution, I want the candidate to tell me why she chose a specific solution. What are the pros and cons of that solution when compared with an alternative? How well will that solution perform when we submit to it a large data set? Will the response time be a linear function of the data set size? Logarithmic? Better? Worse? How can it be improved? Does it use too much memory? How much? What data structure did the candidate use? Can she reason about the pros and cons of such data structure? Did she use a Python dictionary or a Java map? What do those language provided data structures do behind the scenes?</p><h3>But why?</h3><p>The above paragraph may sound like a lot, almost exhausting. But what is the alternative?</p><p>Do you want to have to check every single line of code a software developer produces? Or do you want them to check each other’s work and know you can trust what they did?</p><p>Do you want to feel confident that the software your team produces will perform well and survive the test of time? Or are you willing to take the risk of having to rewrite a lot of it a few months after it goes to production because it was just discovered that the solution can not scale? And not because any one was intentionally hiding something, but because no one in the team could realize the “working” solution was fundamentally flawed.</p><p>Take your time to find the right candidate. That is a worthy investment.</p><h3>Am I asking too much?</h3><p>I believe not. I am aware that not every candidate will answer what I want to hear, perhaps not even half of them.</p><p>Certainly it is not something that will be learned in a 2 months Java, Python or HTML boot camp.</p><p>On the other hand, the basics of what I am talking about are taught early to computer science or software engineering undergraduate students, and then reiterated over and over until they graduate. Any college graduated young software professional have been taught formal courses in algorithms and data structure fundamentals and should be able to use that knowledge in an interview.</p><p>Am I saying that we should only interview bachelors in software related disciplines? Of course not. In a world full of self taught software developers, that would be ignoring a fantastic pool of potential talent with the attitude and drive to thrive. If you are a self taught software developer looking to improve your skills, forget at the moment about learning another programing language or the next NoSQL DB. Get yourself some good algorithms and data structures book as well as a graph theory book, learn about algorithms analysis and complexity, and start a new journey. At the beginning you may feel like you don’t make too much progress, but trust me on this one, it will be one of the best investments you can make in your career.</p><h3>Closing</h3><p>It is my believe that the technical aspects of a software engineer / developer interview should focus on their ability to reason about the quality, pros and cons of the solutions they produce, rather than the ability to produce some solution.</p><p>To be able to evaluate the candidates reasoning, asking them to solve simple problems is better than asking them to solve very complicated ones, or mind teasers or talk a lot about technologies that may become outdated few years down the road.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=853e16fc7953" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Anyone can cook]]></title>
            <link>https://medium.com/@rodrigo.javier.ramirez/https-medium-com-rodrigo-javier-ramirez-anyone-can-cook-e91b2f93bd31?source=rss-4060b04c94e3------2</link>
            <guid isPermaLink="false">https://medium.com/p/e91b2f93bd31</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[interview]]></category>
            <dc:creator><![CDATA[Rodrigo Ramirez]]></dc:creator>
            <pubDate>Mon, 28 Oct 2019 00:12:34 GMT</pubDate>
            <atom:updated>2019-10-31T03:45:33.725Z</atom:updated>
            <content:encoded><![CDATA[<h4>The second most important trait in software engineers</h4><figure><img alt="Knowing many trending technologies is probably not very important" src="https://cdn-images-1.medium.com/max/701/1*2X82W0uIzETTdYYqW3zQ-Q.png" /></figure><p>Do you remember the movie Ratatouille? Anyone can cook, right? But not everyone is a chef. I can cook, sort of, but certainly I am not a chef.</p><p>The software industry is not so different. Anyone can code, or so it seems. The question is what to look for when interviewing candidates for software engineer positions?</p><h3>But, what about the first trait?</h3><p>The single most important quality of a person in any job is a positive attitude. It does not matter how smart a person may be. Without a positive, team oriented, and constructive attitude you rather soon will wish that person was not in your team. Volumes could be written about «brilliant» people that companies let go at the first opportunity because of their toxic attitude with their teammates.</p><p>But attitude is not what this article is about, and honestly, experience has taught me that I am not the best at spotting candidates with difficult personalities.</p><h3>What about all these?</h3><p>Some people may say years of experience, exposure to trending, fancy technologies, or even the ability to solve coding problems in our target programming language are the key. In my opinion none of the above are that important.</p><p>Allow me to explain.</p><p>Years of experience more likely will be vetted by a recruiter even without having too much technical knowledge. Don’t get me wrong, experience is important, but I want good experience, not just the number of years of experience. A person may have many years of experience without having achieved something really good.</p><p>Specific technologies and even programming languages come and go, some ones rather fast. A candidate may be really good with some fancy, trending technology that we are using today. I think this is an important hiring criteria if we are looking for a contractor that will solve a specific problem related to that technology and then go.</p><p>Some people fancy asking for riddles about coins, weights, and many others things that supposedly help assessing how the candidate approaches problems. I believe those mind teasers are nice and even fun, but predict nothing; and likely not even the person asking them was able to find the answer until it was explained to him the first time. I have read that some of the larger companies in tech have banned this type of question from their interview process.</p><h3>OK, what about coding?</h3><p>Of course coding it is fundamental. We are looking for a software engineer, whose main task will very likely to write software, isn’t it?</p><p>Yes. When I interview I ask some rather simple coding problems. And yes, I expect simple elegant answers and perhaps the ability to solve the same problem in a different way. Let’s say a person coded an iterative solution to a question I believe can also be approached with a recursive algorithm. Then very likely I would ask the candidate to code the alternative solution as well.</p><p>But … There is always a but … In today’s world I would expect any serious candidate to have solved many programing problems using online tools like leetcode.com or hackerrank.com before coming to an interview. It is said that successful candidates solve at least 150 coding questions before interviewing with Google or Amazon.</p><p>With the above in mind, chances are that any coding problem I ask, or at least a very similar one, has already being solved by the candidate. For me being a good software engineer is not about memorizing the solutions to a bunch of typical problems. Solving many problems is just the beginning of the journey.</p><h3>Then what? Will you finally tell me?</h3><p>OK. Enough is enough. What I am really looking for when I interview a candidate for a software engineer position is to have a 20 minutes conversation about fundamentals. For me the difference between a programmer and a software engineer, read «cook» vs «chef», is the understanding and ability to reason about fundamentals.</p><p>I am looking for a candidate that can thrive, and for many years grow side by side with the team. A person that can challenge any other in the team and together analyze many aspects of a problem before committing to a solution. Such a person needs to be far more than a coder.</p><p>Back to the coding problem, in addition to perhaps be able to provide more than one solution, I want the candidate to tell me why she chose a specific solution. What are the pros and cons of that solution when compared with an alternative? How well will that solution perform when we submit to it a large data set? Will the response time be a linear function of the data set size? Logarithmic? Better? Worse? How can it be improved? Does it use too much memory? How much? What data structure did the candidate use? Can she reason about the pros and cons of such data structure? Did she use a Python dictionary or a Java map? What do those language provided data structures do behind the scenes?</p><h3>But why?</h3><p>The above paragraph may sound like a lot, almost exhausting. But what is the alternative?</p><p>Do you want to have to check every single line of code a software developer produces? Or do you want them to check each other’s work and know you can trust what they did?</p><p>Do you want to feel confident that the software your team produces will perform well and survive the test of time? Or are you willing to take the risk of having to rewrite a lot of it a few months after it goes to production because it was just discovered that the solution can not scale?</p><p>Take your time to find the right candidate. That is a worthy investment.</p><h3>Am I asking too much?</h3><p>I believe not. I am sadly aware that not every candidate will be able to answer what I want to hear, perhaps not even half of them.</p><p>Certainly it is not something that will be learned in a coding academy for kids or in a 2 months Java, Python or HTML boot camp.</p><p>On the other hand, the basics of what I am talking about are taught early to computer science or software engineering undergraduate students, and then reiterated over and over until they graduate. Any college graduated young software professional have been taught formal courses in algorithms and data structure fundamentals and should be able to use that knowledge in an interview.</p><p>Am I saying that we should only interview bachelors in software related disciplines? Of course not. In a world full of self taught software developers, that would be ignoring a fantastic pool of potential talent. If you are a self taught software developer looking to improve your skills, forget at the moment about learning another programing language or the next NoSQL DB. Get yourself some good algorithms and data structures book as well as a graph theory book, learn about algorithms analysis and complexity, and start a new journey.</p><h3>Closing</h3><p>It is my believe that the technical aspects of a software engineer / developer interview should focus on their ability to reason about the quality, pros and cons of the solutions they produce, rather than the ability to produce some solution.</p><p>To be able to evaluate the candidates reasoning, asking them to solve simple problems is better than asking them to solve very complicated ones, or mind teasers or talk a lot about technologies that may become outdated few years down the road.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e91b2f93bd31" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Compiled vs Interpreted Code Performance]]></title>
            <link>https://medium.com/swlh/compiled-vs-interpreted-code-performance-e1a63299760b?source=rss-4060b04c94e3------2</link>
            <guid isPermaLink="false">https://medium.com/p/e1a63299760b</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[performance-testing]]></category>
            <dc:creator><![CDATA[Rodrigo Ramirez]]></dc:creator>
            <pubDate>Mon, 07 Oct 2019 00:44:22 GMT</pubDate>
            <atom:updated>2019-10-21T09:33:56.672Z</atom:updated>
            <content:encoded><![CDATA[<p>Comparing Python, Java and Go performance</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/839/1*sqStI0fcUbI4-FpeNbc4cw.png" /></figure><p>I am a chauvinist of compiled languages. I have always been. While interpreted languages may help a developer to start writing and testing code faster, I see a compiler as the best possible long term investment. The way I see it you get at least 2 huge advantages when your code is compiled:</p><ul><li>You get all your code checked every time you change it, even before you can start using it.</li><li>You get much faster execution times. Depending on the particulars of the tasks at hand it may translate in significantly lower infrastructure costs, perhaps even an order of magnitude lower for installations with really high traffic.</li></ul><p>How much faster is compiled over interpreted code is one of the main reasons why I am writing this article.</p><p>Given my acknowledged preference of compiled over interpreted languages I am now facing a challenge: I have inherited this vast amount of code I have vested interest in, fully written in Python, whose better known and tested implementations are based on code interpreters, not compilers. What should I do with it? Rewrite all of it? Part of it? None?</p><h3>Preconceptions</h3><p>In this blog I examine some preconceptions I have by comparing the performance of different tasks using different programing languages: Java, Go and Python. Why Python is obvious, that is what I am evaluating to be replaced or not. Java because I have been a fan of it for almost 2 decades, seeing it maturing, while performance and functionality got better and better. Finally I came in the last 2 years to start using and really liking Go. While there are elements of Java I still miss in Go, such as class inheritance, the language syntax is clean and compact, compilation and execution are fast, the generated code compact and its out of the box <em>go-routines</em> based approach to concurrency is really elegant.</p><p>Some of the preconceptions I mentioned are:</p><ul><li>Compiled code runs at least one order of magnitude faster than interpreted code. I base this opinion on a previous experience comparing the performance of Java code before and after the JIT has compiled the byte code. I have found the relation to be approximatelly 30 to 1.</li><li>Go code runs a bit faster than Java. I remember some past tests done in my previous job that found Go to be up to 30% faster than Java in some tasks, but I have read recent blogs claiming Java to be a bit faster than Go.</li></ul><h3>First Test</h3><p>I took advantage of the java code in another article I wrote recently: <a href="https://medium.com/@rodrigo.javier.ramirez/understanding-java-jit-compiler-787f87daa110">https://medium.com/@rodrigo.javier.ramirez/understanding-java-jit-compiler-787f87daa110</a>. I wrote it again in Python and Go and compared the results. The code calculates and prints the execution time in nanoseconds of 200 batches, each executing 50 times the fibonacci number of 100.</p><p>The code used to produce the results can be found at: <a href="https://github.com/rodrigoramirez/fibonacci">https://github.com/rodrigoramirez/fibonacci</a>.</p><p>The output, skipping the initial lines for each of Java, Go and Python looked like:</p><pre>Java   Go    Python<br>...<br>122    123   11683<br>119    107   11539<br>123    104   11358<br>120    115   11926<br>119    118   11973<br>120    104   11377<br>109    103   12960<br>127    122   15683<br>112    106   11482<br>...</pre><p>The average times in nanoseconds, ignoring again the initial lines is:</p><pre>Java   Go    Python<br>130    105   10050</pre><p>So calculating fibonacci numbers Java code is a bit slower than Go code, about 24% slower this time. Python, on the other hand is almost 100 times slower than Go, 9458% slower according to my test.</p><p>This test confirmed my original ideas about Java and Go. But what a nasty surprise was to see how much worse interpreted Python performs. Not one order of magnitude worse, as I suspected, but two.</p><p>I wonder with results like this why Python is used so much?</p><p>The first thought that comes to mind is that a lot of people pays more attention to code simplicity and ability to quickly achieve results over performance and long term costs. I believe this to be the case of data scientists; being Python well known for the vast amount of libraries existing why bother looking around? Optimization can certainly come later.</p><p>A second idea is simply than many people never measure or compare their results with alternative implementations. With so many startups and a fierce competition to get something out, perhaps the optimization phase never arrives.</p><p>A third option may be that there are ways to make the same code written in Python perform much faster.</p><h3>What About Compiled Python</h3><p>After some research I decided to test the same Python code using PyPy, a Python implementation written in Python, that includes a JIT compiler just like Java does. As with Java we need to ignore the initial output and skip the part produced while the code is still being JIT compiled. Cutting to the chase the averages table including a PyPy column looks like:</p><pre>Java   Go    Python    PyPy<br>130    105   10050     1887</pre><p>While average response time using PyPy is more than 5 times faster than Python, it is still more than 20 times slower than Go.</p><h3>The Need for Additional Tests</h3><p>The test above is rather a generic test focussed on integer arithmetic. Going back to the Python code I mentioned in the introduction, I will need to pay attention to:</p><ul><li>I/O via Kafka, HTTP listeners and databases</li><li>Parse JSON messages</li></ul><h3>Wrapping Up</h3><p>This article shows that processing simple arithmetic operations, code written in Go is a bit faster than its Java counterpart, and 2 orders of magnitude faster that interpreted Python code.</p><p>Personally I would not replace a well known and tested Java code with its Go equivalent just based on these results.</p><p>On the other hand, the test shows that Python code on a high traffic critical path may not be a good option. If you face this situation, consider using a Python compiler as a short term workaround.</p><p>To make the final decision of what should be rewritten and when, other factors not explored in this post should be considered, such as how I/O intensive vs CPU intensive is the code to be potentially rewritten.</p><h3>From the Comments</h3><p>The comment from Shaun Dream made me realize the code I wrote for Go and Java, using 64 bit integers can only compute fibonacci 92 before the results get rigged by aritmethic overflow. Having said that, it is my opinion that the reasoning and conclusions on this article remain valid.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e1a63299760b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/compiled-vs-interpreted-code-performance-e1a63299760b">Compiled vs Interpreted Code Performance</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Java JIT Compiler]]></title>
            <link>https://medium.com/@rodrigo.javier.ramirez/understanding-java-jit-compiler-787f87daa110?source=rss-4060b04c94e3------2</link>
            <guid isPermaLink="false">https://medium.com/p/787f87daa110</guid>
            <category><![CDATA[jit]]></category>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[performance-testing]]></category>
            <category><![CDATA[just-in-time-compiler]]></category>
            <dc:creator><![CDATA[Rodrigo Ramirez]]></dc:creator>
            <pubDate>Mon, 15 Jul 2019 01:01:03 GMT</pubDate>
            <atom:updated>2019-07-15T01:33:49.515Z</atom:updated>
            <content:encoded><![CDATA[<p>Few years ago I wrote a blog evaluating solutions for a performance problem I had faced some days before. Checking the blog again I realized that I failed to mention that some performance improvement while the test was running, happened because the Java JIT (just in time) compiler had compiled the code and hence it was running much faster after several iterations.</p><p>But, what is this JIT compiler (we will use JIT for short) and why it is important? I’d bet many novice Java developers are not aware of it and how dramatically performance changes as the JIT goes doing its job. Over the years I have had many discussions about the topic I will discuss in this page and I have even seen executives made very expensive and unnecessary decisions for not understanding this topic well enough.</p><p>It is well known that code written in a compiled programing language executes much faster than an code written in an interpreted programing language. Also, for most programing languages it is easy enough to know, whether they are either compiled or interpreted. For example Phyton and most shell scripting languages are interpreted while C++ and Go Lang are compiled. Then, what about Java? The answer is that Java is both, interpreted and compiled, and this surely requires some explanation.</p><p>Running Java code from the command line takes 2 steps. First you use <strong>javac</strong> command to “compile” the source code and then you use the <strong>java</strong> command to execute the compiled code. One may ask, if the code is compiled to machine language then why we need the java command to execute it? The answer is simple: becuse the code is not compiled to machine language. What? another one may ask? Didn’t you just say that we compile the Java code before executing it? Yes, Java code is compiled, but not to machine language. It is compiled to a JVM specific format called byte code that the JVM interprets when the java command is issued.</p><p>From the paragraph above we get that the Java code is compiled to byte code and then interpreted by the JVM. Up to this point, performance wise we are talking about an interpreted language, and now is when the JIT enters the game. As the JVM executes the byte code, it keeps track of how many times each method is being called and, when a predefined threshold for a method is reached, bingo, that method is compiled on the fly (just in time) to machine language. From that moment on the machine language compiled method is used, which results in a much faster execution process. The process described is used not just with our proprietary code, but with the standard Java libraries as well. Eventually, after some time, almost all the code is compiled to machine language.</p><h3>Test and Results</h3><p>To visualize the performance gains after the JIT compiles the code let’s run the following example that executes 100 batches of 50 calculations of the fibonacci number of 100 (f(100) for short) and after each batch prints average execution time for f(100).</p><pre>package rr.jittest;<br><br><em>/**<br> * Class used to measure the effect of JIT on a simple calculation.<br> * It calculates the fibonacci of some number many times,<br> * calculating and printing the average time per execution. The <br> * process is repeated many times to understand the long term <br> * effect.<br> * <br> * </em><strong><em>@author </em></strong><em>Rodrigo Ramirez<br> *<br> */<br></em>public class Fibonacci {<br><br>    <em>/**<br>     * Calculates the Fibonacci of n :<br>     * </em><strong><em>@param </em></strong><em>n<br>     * </em><strong><em>@return </em></strong><em>f(n)<br>     */<br>    </em>public static int f(int n) {<br>        if (n &lt;= 2) {<br>            return 1;<br>        }<br>        int n1 = 1;<br>        int n2 = 1;<br>        int result = 0;<br><br>        for(int i = 3; i &lt;= n; i++ ) {<br>            result = n1 + n2;<br>            n2 = n1;<br>            n1 = result;<br>        }<br><br>        return result;<br>    }<br><br>    <em>/**<br>     * Prints the average time it takes to calculate f(n)<br>     * </em><strong><em>@param </em></strong><em>args<br>     */<br>    </em>public static void trackExecutionSpeed() {<br>        System.<em>out</em>.println(<br>               &quot;Average time to execute f(100) in nanoseconds&quot;);<br>        for(int i = 0; i &lt; 100; i++) {<br>            long startTime = System.<em>nanoTime</em>();<br>            for(int j = 0; j &lt; 50; j++) {<br>                <em>f</em>(100);<br>            }<br>            long totalTime = System.<em>nanoTime</em>() - startTime;<br>            System.<em>out</em>.println(String.<em>format</em>(&quot;%f&quot;, <br>                               totalTime / 50.0));<br>        }<br>    }<br><br>    public static void main(String[] args) {<br>        <em>trackExecutionSpeed</em>();<br>    }<br>}</pre><p>The initial and final lines in the output may look as follows:</p><pre>Average time to execute f(100) in nanoseconds<br>3144.700000<br>3528.540000<br>11019.200000<br>625.360000<br>765.600000<br>568.380000<br>…<br>120.180000<br>Process finished with exit code 0</pre><p>Using excel we created a line chart with the above output. The results follow:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7eN-MpO6SyeCYdXVB8IKiQ.png" /></figure><p>In the chart above you can clearly see that average execution times start high and as time passes, go down several times until they stabilize. In our example the machine compiled code executes about 30 times faster than the byte code. It is also evident that some times there are big spikes in the average execution time before it goes down even more than the previous batches. This the penalty of JIT compilation while it happens.</p><p>Checking the results in more detail we see:</p><ul><li>Two batches of 50 iterations each one taking an average of some more than 3000 nanoseconds each.</li><li>One big spike, presumably due to JIT compilation, while the third batch was executing.</li><li>About eleven batches with execution averages around 600 nanoseconds.</li><li>One or two more compilation spikes.</li><li>Batches of 120 nanoseconds average execution time for the rest of the test.</li></ul><h3>Effect on load and stress testing</h3><p>Clearly any load or stress test will produce very different results before and after the JIT compiles most or all of the methods used in the test. For code that is intended to be used in production over extended periods of time, it makes sense to discard the initial iterations and use the results after the execution time stabilizes for a constant load, a sign that the code is fully compiled to machine language.</p><h3>Server warming up</h3><p>Depending on your specific scenario it may be unacceptable to start with a higher execution time, if even for a few iterations before execution times stabilize after full compilation. If that is your case, it makes sense to “warm it up” by using test data forcing the JIT compilation before the server is used in production.</p><h3>Scripts vs Server Code</h3><p>It should be clear now that before JIT compiles your code, you experience performance typically associated with interpreted code, not machine language compiled code. This is the case with code that executes once and exists, for example code that executes from a cron job task, uploads a few files to a server and exits.</p><p>JIT compiled benefits are normally seen on code that starts executing and stays running for long periods of time like happens on web, application or database servers, as well as code in embedded devices that may start when you power the device and keep running until the device is disconnected.</p><h3>Environment used for execution</h3><p>For the test in this post the following conditions were used:</p><ul><li>MacBook Pro 17&#39;’ late 2010.</li><li>JDK 1.8</li><li>-Xms10m -Xmx10m settings, to minimize the effect of garbage collection on the test.</li></ul><h3>Where to go from here</h3><p>The purpose of this post is to help the reader understand what the JIT compiler is and how it affects execution. There is far more to understand if this is your area of interest. I suggest to look for posts explaining how to tune your JIT compiler; note that this information may be specific to your JVM distribution, particularly on embedded platforms. You can find information explaining:</p><ul><li>Details about the order and frequency required before code is compiled.</li><li>Startup switches to tune the JIT compiler for server vs script like scenarios.</li><li>Controlling how setters and getters are optimized.</li><li>Controlling whether all code should be compiled or just a few classes; useful in embedded platforms with limited memory.</li></ul><h3>Closing comments</h3><p>In this post I discussed how Java JIT compiler works and created a test to help the reader visualize its benefits and penalties, particularly the fact that JIT compiled code runs about 30 times faster than not compiled code. I discussed how to manage JIT compilation effects on some typical situations like load testing and server warm up as well as some scenarios that may not benefit from JIT compilation.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=787f87daa110" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>