<?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 Ryan Kuang on Medium]]></title>
        <description><![CDATA[Stories by Ryan Kuang on Medium]]></description>
        <link>https://medium.com/@ryan_k_uncountable?source=rss-4fe974c57b07------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*E7UlxhENfbInSSIRE8tKDQ.jpeg</url>
            <title>Stories by Ryan Kuang on Medium</title>
            <link>https://medium.com/@ryan_k_uncountable?source=rss-4fe974c57b07------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 23:07:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ryan_k_uncountable/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[Simple Python Profiling with the @profile Decorator]]></title>
            <link>https://medium.com/uncountable-engineering/pythons-line-profiler-32df2b07b290?source=rss-4fe974c57b07------2</link>
            <guid isPermaLink="false">https://medium.com/p/32df2b07b290</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[optimization]]></category>
            <dc:creator><![CDATA[Ryan Kuang]]></dc:creator>
            <pubDate>Fri, 16 Apr 2021 19:30:32 GMT</pubDate>
            <atom:updated>2021-06-28T21:21:45.292Z</atom:updated>
            <content:encoded><![CDATA[<h4>Code, Format, Repeat #1</h4><h4>One weird trick for pain-free performance profiling</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qOj93vsx0URZi-FBvPCh6A.png" /><figcaption>A line profiler hard at work // Illustration by <a href="https://www.imcathy.com/">Cathy Yang</a></figcaption></figure><p><em>#Uncountable is hiring! To help us accelerate the future of materials development, check out our </em><a href="https://www.uncountable.com/working-at-uncountable"><em>Careers</em></a><em> page.</em></p><p>Away of analyzing the performance of any given function or program is to use profilers during its execution. Profilers can help us understand timing, memory usage, and other pertinent information about code. The key to using profilers is to determine which portion of the code is slow or computationally expensive and assist the process of catching errors for optimization.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/774/1*t667ybeXNiBS0kzc2-gJcg.png" /><figcaption>The never-ending profiling process (Illustration by Josh Wagner)</figcaption></figure><p>One particular library we use often at <a href="https://www.uncountable.com/working-at-uncountable">Uncountable</a> is the Python <a href="https://github.com/pyutils/line_profiler">line profiler</a>.</p><p>This library is helpful when digging into a specific function to find the exact lines that take the most time to run. This is especially useful in diagnosing large functions and finding the hotspots that cause performance issues, which may not be apparent to the naked eye. For example, a single line that uses a function from an external library can trigger a lot of hidden computation in the background. This function call can take a lot of time to run, although it may appear to be simple to use. Without the profiler, we wouldn’t know what was slowing down the code during our diagnosis of poor performance.</p><p>The line_profiler can be installed simply using pip:</p><pre>$ python -m pip install line_profiler</pre><p>We can naively use the line profiler, but the library limits its uses to the command line, which makes using it in flask more inconvenient.<em> </em>Instead, we can create the following decorator:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4b796c4aab681aa9fb03598c9515898b/href">https://medium.com/media/4b796c4aab681aa9fb03598c9515898b/href</a></iframe><p>In addition, we can also create a helper function to print out the profile statistics:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/01d2d3849d0cdb71b8d58aee69f449f4/href">https://medium.com/media/01d2d3849d0cdb71b8d58aee69f449f4/href</a></iframe><p>To use the line profiler, we will import our decorator and apply it to the function we wish to diagnose.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1480aad989685facda305e368c1cb713/href">https://medium.com/media/1480aad989685facda305e368c1cb713/href</a></iframe><p>After running our function, the console should output the profiler results to our program’s standard output stream in the following format:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/faaf8f1c3c582ae446baa05094831af5/href">https://medium.com/media/faaf8f1c3c582ae446baa05094831af5/href</a></iframe><p>The code is printed along with information generated by the profiler, which includes:</p><ul><li>Line number</li><li>Hits, the number of times the line is run</li><li>Time: the total amount of time this line executed across all hits</li><li>Per Hit: the average amount of time</li><li>% Time: The percentage of time spent on that line relative to the total amount of recorded time spent in the function.</li></ul><p>In our next blog post on profiling, we will walk through some common optimization examples. <strong>[u]</strong></p><p><em>#Uncountable is hiring! To help us accelerate the future of materials development, check out our </em><a href="https://www.uncountable.com/working-at-uncountable"><em>Careers</em></a><em> page.</em></p><pre><em>Ryan Kuang was previously at the University of Chicago, where he received degrees in Economics and Computer Science. At Uncountable, he works as a fullstack engineer on platform development. In his free time, he is a massive foodie, enjoys hikes, and dabbles in crypto.</em></pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=32df2b07b290" width="1" height="1" alt=""><hr><p><a href="https://medium.com/uncountable-engineering/pythons-line-profiler-32df2b07b290">Simple Python Profiling with the @profile Decorator</a> was originally published in <a href="https://medium.com/uncountable-engineering">Uncountable Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>