<?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:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0"><channel><title><![CDATA[StuffAndCode Newsletter]]></title><description><![CDATA[Envie de step-up en Python et de sortir des sentiers battus ? 

Abonnez-vous à la newsletter pour recevoir chaque semaine des articles sur des sujets avancés en Python !  ]]></description><link>https://blog.stuffandcode.com</link><image><url>https://substackcdn.com/image/fetch/$s_!1wnt!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F844c9b33-a381-4d38-9c3d-274d23b322af_1024x1024.png</url><title>StuffAndCode Newsletter</title><link>https://blog.stuffandcode.com</link></image><generator>Substack</generator><lastBuildDate>Thu, 07 May 2026 11:29:59 GMT</lastBuildDate><atom:link href="https://blog.stuffandcode.com/feed" rel="self" type="application/rss+xml"/><copyright><![CDATA[Téva KRIEF]]></copyright><language><![CDATA[fr]]></language><webMaster><![CDATA[stuffandcode@substack.com]]></webMaster><itunes:owner><itunes:email><![CDATA[stuffandcode@substack.com]]></itunes:email><itunes:name><![CDATA[Téva KRIEF]]></itunes:name></itunes:owner><itunes:author><![CDATA[Téva KRIEF]]></itunes:author><googleplay:owner><![CDATA[stuffandcode@substack.com]]></googleplay:owner><googleplay:email><![CDATA[stuffandcode@substack.com]]></googleplay:email><googleplay:author><![CDATA[Téva KRIEF]]></googleplay:author><itunes:block><![CDATA[Yes]]></itunes:block><item><title><![CDATA[Profiling speed, memory & SQL : what tools ? Part 1]]></title><description><![CDATA[There are many tools available for profiling Python code, each with its own strengths and weaknesses. Let&#8217;s take a look at which tool is best suited to which use case.]]></description><link>https://blog.stuffandcode.com/p/profiling-speed-memory-and-sql-what</link><guid isPermaLink="false">https://blog.stuffandcode.com/p/profiling-speed-memory-and-sql-what</guid><dc:creator><![CDATA[Téva KRIEF]]></dc:creator><pubDate>Wed, 02 Apr 2025 12:58:47 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!sxo3!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65b261b4-a663-4863-addb-4ffc14db39f4_1736x2240.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p></p><p>We&#8217;ll be running profiling on the same code with different tools so you can see the output generated. At the end of this article we&#8217;ll make a comparison of the tools.  And when to use which one.</p><p></p><h2>The tools</h2><ul><li><p><strong><a href="https://github.com/joerick/pyinstrument">PyInstrument</a></strong>: Statistical profiler, great for getting a <strong>high-level overview</strong> of what your code is doing.</p></li><li><p><strong><a href="https://docs.python.org/3/library/profile.html#module-cProfile">cProfile</a></strong>: Deterministic profiler,  useful for getting a <strong>detailed breakdown of every function call</strong>.</p></li><li><p><strong><a href="https://github.com/benfred/py-spy/">Py-Spy</a></strong>: Sampling profiler that can <strong>attach to running processes</strong>, great for <strong>production debugging</strong>.</p></li><li><p><strong><a href="https://github.com/plasma-umass/scalene">Scalene</a></strong>: A powerful profiler that tracks <strong>CPU time, wall time, and memory</strong>.</p></li><li><p><code>time</code><strong> (Linux shell)</strong>: Simple but effective for measuring <strong>total runtime</strong>, including imports, I/O, and startup overhead.</p></li></ul><p></p><h2>The code we&#8217;ll profile </h2><p><strong><a href="https://adventofcode.com/2024/day/2">Day 2 of Advent of Code 2024</a></strong> (yeah, shame on me,  I only did Day 1 last year, so I did the second day for this example&#8230;) </p><p><br>I&#8217;ve implemented a solution to the <strong>second part</strong> of the challenge (usually the trickier one).<br>To better highlight potential optimizations (and make profiling results more meaningful), I&#8217;ve deliberately increased the input size,  so we can observe <strong>where time or memory is being consumed</strong>.</p><p></p><p>Here&#8217;s what I came up with, it could be improved (that&#8217;s the point) but it works.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!sxo3!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65b261b4-a663-4863-addb-4ffc14db39f4_1736x2240.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!sxo3!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65b261b4-a663-4863-addb-4ffc14db39f4_1736x2240.png 424w, https://substackcdn.com/image/fetch/$s_!sxo3!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65b261b4-a663-4863-addb-4ffc14db39f4_1736x2240.png 848w, https://substackcdn.com/image/fetch/$s_!sxo3!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65b261b4-a663-4863-addb-4ffc14db39f4_1736x2240.png 1272w, https://substackcdn.com/image/fetch/$s_!sxo3!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65b261b4-a663-4863-addb-4ffc14db39f4_1736x2240.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!sxo3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65b261b4-a663-4863-addb-4ffc14db39f4_1736x2240.png" width="1456" height="1879" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/65b261b4-a663-4863-addb-4ffc14db39f4_1736x2240.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1879,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:399620,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://blog.stuffandcode.com/i/160346661?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65b261b4-a663-4863-addb-4ffc14db39f4_1736x2240.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!sxo3!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65b261b4-a663-4863-addb-4ffc14db39f4_1736x2240.png 424w, https://substackcdn.com/image/fetch/$s_!sxo3!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65b261b4-a663-4863-addb-4ffc14db39f4_1736x2240.png 848w, https://substackcdn.com/image/fetch/$s_!sxo3!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65b261b4-a663-4863-addb-4ffc14db39f4_1736x2240.png 1272w, https://substackcdn.com/image/fetch/$s_!sxo3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65b261b4-a663-4863-addb-4ffc14db39f4_1736x2240.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p> </p><p></p><h3>time</h3><blockquote><p><em><strong>time python aoc2-2.py</strong></em></p></blockquote><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!reJ5!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7635f4e9-1151-4095-8147-dd6a3a1104f7_1460x64.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!reJ5!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7635f4e9-1151-4095-8147-dd6a3a1104f7_1460x64.png 424w, https://substackcdn.com/image/fetch/$s_!reJ5!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7635f4e9-1151-4095-8147-dd6a3a1104f7_1460x64.png 848w, https://substackcdn.com/image/fetch/$s_!reJ5!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7635f4e9-1151-4095-8147-dd6a3a1104f7_1460x64.png 1272w, https://substackcdn.com/image/fetch/$s_!reJ5!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7635f4e9-1151-4095-8147-dd6a3a1104f7_1460x64.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!reJ5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7635f4e9-1151-4095-8147-dd6a3a1104f7_1460x64.png" width="1456" height="64" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7635f4e9-1151-4095-8147-dd6a3a1104f7_1460x64.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:64,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:21044,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://blog.stuffandcode.com/i/160346661?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7635f4e9-1151-4095-8147-dd6a3a1104f7_1460x64.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!reJ5!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7635f4e9-1151-4095-8147-dd6a3a1104f7_1460x64.png 424w, https://substackcdn.com/image/fetch/$s_!reJ5!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7635f4e9-1151-4095-8147-dd6a3a1104f7_1460x64.png 848w, https://substackcdn.com/image/fetch/$s_!reJ5!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7635f4e9-1151-4095-8147-dd6a3a1104f7_1460x64.png 1272w, https://substackcdn.com/image/fetch/$s_!reJ5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7635f4e9-1151-4095-8147-dd6a3a1104f7_1460x64.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>The classic <code>time</code> command gives us a quick look at how long the entire script took to execute. In this example, the total runtime is reported as <strong>2.850 seconds</strong>, with almost all of it spent in user space (<code>2.81s user</code>) and very little in system calls. This tool is extremely simple but useful to establish a performance baseline. <strong>However, it gives us no insight into </strong><em><strong>what</strong></em><strong> inside the program took time</strong>,  just that it took time.</p><p></p><p></p><h3>PyInstrument: </h3><blockquote><p><em><strong>pyinstrument -r html aoc2-2.py</strong></em></p></blockquote><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!y7ag!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a36f576-70d5-47d2-a734-74a11c1cd8cd_944x934.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!y7ag!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a36f576-70d5-47d2-a734-74a11c1cd8cd_944x934.png 424w, https://substackcdn.com/image/fetch/$s_!y7ag!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a36f576-70d5-47d2-a734-74a11c1cd8cd_944x934.png 848w, https://substackcdn.com/image/fetch/$s_!y7ag!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a36f576-70d5-47d2-a734-74a11c1cd8cd_944x934.png 1272w, https://substackcdn.com/image/fetch/$s_!y7ag!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a36f576-70d5-47d2-a734-74a11c1cd8cd_944x934.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!y7ag!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a36f576-70d5-47d2-a734-74a11c1cd8cd_944x934.png" width="944" height="934" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4a36f576-70d5-47d2-a734-74a11c1cd8cd_944x934.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:934,&quot;width&quot;:944,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:191719,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://blog.stuffandcode.com/i/160346661?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a36f576-70d5-47d2-a734-74a11c1cd8cd_944x934.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!y7ag!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a36f576-70d5-47d2-a734-74a11c1cd8cd_944x934.png 424w, https://substackcdn.com/image/fetch/$s_!y7ag!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a36f576-70d5-47d2-a734-74a11c1cd8cd_944x934.png 848w, https://substackcdn.com/image/fetch/$s_!y7ag!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a36f576-70d5-47d2-a734-74a11c1cd8cd_944x934.png 1272w, https://substackcdn.com/image/fetch/$s_!y7ag!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a36f576-70d5-47d2-a734-74a11c1cd8cd_944x934.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>PyInstrument offers a <strong>view of where your code spent its time</strong>, using stack sampling. In the screenshot, we can see that most of the time is spent inside the <code>main</code> function, and more precisely inside a generator expression and the <code>check_is_safe</code> function. PyInstrument makes it easy to spot where time accumulates.<br><br>Also, the interface is clear and beautiful.</p><p></p><p></p><h3>cProfile </h3><blockquote><p><em><strong>python -m cProfile aoc2-2.py -s cumtime </strong></em></p></blockquote><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Epdv!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feee566ae-a748-4fa8-b17b-451771466a16_2140x1210.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Epdv!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feee566ae-a748-4fa8-b17b-451771466a16_2140x1210.png 424w, https://substackcdn.com/image/fetch/$s_!Epdv!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feee566ae-a748-4fa8-b17b-451771466a16_2140x1210.png 848w, https://substackcdn.com/image/fetch/$s_!Epdv!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feee566ae-a748-4fa8-b17b-451771466a16_2140x1210.png 1272w, https://substackcdn.com/image/fetch/$s_!Epdv!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feee566ae-a748-4fa8-b17b-451771466a16_2140x1210.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Epdv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feee566ae-a748-4fa8-b17b-451771466a16_2140x1210.png" width="1456" height="823" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/eee566ae-a748-4fa8-b17b-451771466a16_2140x1210.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:823,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:289910,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://blog.stuffandcode.com/i/160346661?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feee566ae-a748-4fa8-b17b-451771466a16_2140x1210.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Epdv!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feee566ae-a748-4fa8-b17b-451771466a16_2140x1210.png 424w, https://substackcdn.com/image/fetch/$s_!Epdv!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feee566ae-a748-4fa8-b17b-451771466a16_2140x1210.png 848w, https://substackcdn.com/image/fetch/$s_!Epdv!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feee566ae-a748-4fa8-b17b-451771466a16_2140x1210.png 1272w, https://substackcdn.com/image/fetch/$s_!Epdv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feee566ae-a748-4fa8-b17b-451771466a16_2140x1210.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>With cProfile, we get a detailed view of function calls, how many times each was called, the total time spent, and how it contributes to cumulative runtime. In this case, <code>check_is_safe</code> was called over 5 million times, and <code>sorted</code> and <code>abs</code> were also heavily used. This profiler is very precise.</p><p>Still, it&#8217;s great for seeing <strong>exact function-level cost</strong> and how often they&#8217;re triggered.<br><br>I personally like to start with PyInstrument to get a rough idea and then use cProfile. Since it&#8217;s a deterministic profiler, the overhead is superior to tools like PyInstrument.</p><p></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.stuffandcode.com/subscribe?&quot;,&quot;text&quot;:&quot;S'abonner&quot;,&quot;language&quot;:&quot;fr&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption"><strong>Did you learn something ? Subscribe for free to receive new posts.</strong></p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Tapez votre e-mail&#8230;" tabindex="-1"><input type="submit" class="button primary" value="S'abonner"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p></p><p></p><h3>py-spy</h3><blockquote><p><em><strong>sudo py-spy record -o profile.svg -- python aoc2-2.py</strong></em></p></blockquote><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!1ALp!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2a8aa08-2057-4bed-9e3b-dbc99ef9d525_2480x548.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!1ALp!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2a8aa08-2057-4bed-9e3b-dbc99ef9d525_2480x548.png 424w, https://substackcdn.com/image/fetch/$s_!1ALp!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2a8aa08-2057-4bed-9e3b-dbc99ef9d525_2480x548.png 848w, https://substackcdn.com/image/fetch/$s_!1ALp!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2a8aa08-2057-4bed-9e3b-dbc99ef9d525_2480x548.png 1272w, https://substackcdn.com/image/fetch/$s_!1ALp!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2a8aa08-2057-4bed-9e3b-dbc99ef9d525_2480x548.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!1ALp!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2a8aa08-2057-4bed-9e3b-dbc99ef9d525_2480x548.png" width="1456" height="322" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f2a8aa08-2057-4bed-9e3b-dbc99ef9d525_2480x548.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:322,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!1ALp!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2a8aa08-2057-4bed-9e3b-dbc99ef9d525_2480x548.png 424w, https://substackcdn.com/image/fetch/$s_!1ALp!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2a8aa08-2057-4bed-9e3b-dbc99ef9d525_2480x548.png 848w, https://substackcdn.com/image/fetch/$s_!1ALp!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2a8aa08-2057-4bed-9e3b-dbc99ef9d525_2480x548.png 1272w, https://substackcdn.com/image/fetch/$s_!1ALp!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2a8aa08-2057-4bed-9e3b-dbc99ef9d525_2480x548.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Py-Spy generates a <strong>flame graph</strong>, which visualizes stack traces over time. In this case, we see a wide block for <code>&lt;module&gt;</code> and <code>main</code>, then narrower blocks representing the generator expression and <code>check_is_safe</code>.  This tool is great for <strong>profiling production code</strong> or long-running scripts without modifying source code or restarting processes. It gives a quick visual cue about <strong>where time is spent</strong>, though not as detailed as line-level profilers.</p><p></p><p>I like this tool, but I only use it when <strong>I need to debug something that is already running and I cannot restart</strong> or reproduce locally. It also could be used to see where a program is stuck. It has very low overhead, and run in a separate process, so it should not impact your production code.</p><p></p><h3>Scalene</h3><blockquote><p><em><strong>scalene aoc2-2.py</strong></em></p></blockquote><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!NNet!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0b81289-ee5a-423f-be46-10947782f06c_3400x1792.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!NNet!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0b81289-ee5a-423f-be46-10947782f06c_3400x1792.png 424w, https://substackcdn.com/image/fetch/$s_!NNet!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0b81289-ee5a-423f-be46-10947782f06c_3400x1792.png 848w, https://substackcdn.com/image/fetch/$s_!NNet!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0b81289-ee5a-423f-be46-10947782f06c_3400x1792.png 1272w, https://substackcdn.com/image/fetch/$s_!NNet!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0b81289-ee5a-423f-be46-10947782f06c_3400x1792.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!NNet!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0b81289-ee5a-423f-be46-10947782f06c_3400x1792.png" width="1456" height="767" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b0b81289-ee5a-423f-be46-10947782f06c_3400x1792.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:767,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:579336,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://blog.stuffandcode.com/i/160346661?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0b81289-ee5a-423f-be46-10947782f06c_3400x1792.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!NNet!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0b81289-ee5a-423f-be46-10947782f06c_3400x1792.png 424w, https://substackcdn.com/image/fetch/$s_!NNet!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0b81289-ee5a-423f-be46-10947782f06c_3400x1792.png 848w, https://substackcdn.com/image/fetch/$s_!NNet!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0b81289-ee5a-423f-be46-10947782f06c_3400x1792.png 1272w, https://substackcdn.com/image/fetch/$s_!NNet!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0b81289-ee5a-423f-be46-10947782f06c_3400x1792.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Scalene combines <strong>CPU profiling, memory tracking, and even line-level timing</strong> into one HTML report. In the screenshot, we see that the <code>check_is_safe</code> function is a hotspot, and memory usage spikes within that block. It even highlights how much time is spent on each line. This tool is ideal when you want to understand not just <em>how long</em> things take, but also <strong>how much memory they consume</strong>, line by line.</p><p></p><p></p><h2>What would TK do ? My workflow. </h2><ul><li><p>Start with <code>time</code> if your script is easy to run and you just want a quick sense of how long it takes overall.</p><p></p></li><li><p>Then use <strong>PyInstrument</strong> to get a <strong>high-level overview</strong> of where the bottlenecks are. It&#8217;s fast, has low overhead, and gives a clear call-stack timeline. It has amazing integrations with web frameworks and all kind of things you can run into.</p></li></ul><p></p><ul><li><p>If you want to <strong>dig deeper and optimize specific functions</strong>, reach for <strong>cProfile</strong>. It&#8217;ll give you exact call counts and timings, which is great for tight loops or recursive code. The overhead is higher though.</p><p></p></li><li><p>When you&#8217;re dealing with something running <strong>in production</strong>, or hard to reproduce locally, <strong>Py-Spy</strong> is your go-to tool. You can attach it to a live process without restarting anything.</p></li></ul><p></p><ul><li><p>And finally, if you want to get performance &amp; memory at the same time, <strong>Scalene</strong> gives you per-line CPU, wall time, and memory usage in a single report. I discovered this tool recently, I need to dig deeper.</p><p></p></li></ul><p><strong>Performance is just one part of the story.</strong><br><strong>Next up</strong>: tackling memory usage, ORM madness, and other sneaky slowdowns. Stay tuned!</p><p></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.stuffandcode.com/subscribe?&quot;,&quot;text&quot;:&quot;S'abonner&quot;,&quot;language&quot;:&quot;fr&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption"><strong>Did you learn something ? Subscribe for free to receive new posts</strong></p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Tapez votre e-mail&#8230;" tabindex="-1"><input type="submit" class="button primary" value="S'abonner"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p></p><p></p>]]></content:encoded></item><item><title><![CDATA[Welcome to the Hall Of Fails : Part 1]]></title><description><![CDATA[Entrepreneurship is a journey, and I do have a lot of fails. Wanted to share some with you.]]></description><link>https://blog.stuffandcode.com/p/welcome-to-the-hall-of-fails-part</link><guid isPermaLink="false">https://blog.stuffandcode.com/p/welcome-to-the-hall-of-fails-part</guid><dc:creator><![CDATA[Téva KRIEF]]></dc:creator><pubDate>Wed, 12 Mar 2025 00:01:05 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fadcf502a-63b5-4ba8-99a5-c5e2e3fe60e1_1428x1133.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Yeah, so I&#8217;ve been working on side projects for a while now. Listing everything I did and what went wrong would be too time consuming, but I can share some of it with you, and also it&#8217;s kind of a reminder of the journey for me. <br></p><p>Since I do freelance work, I only work a few months each year to have more time to spend on my projects. And in 2024, I decided to go all in. Meaning that from November 2023 to today, I&#8217;ve only been working on my side projects.</p><p><br><strong>Let&#8217;s start from early 2024:</strong></p><h2><strong>January 2024:</strong> <em>pinock.io</em></h2><p>For a few months, I had been working with a friend on a B2B tool called Pinock.io. It was designed for IT consulting firms (ESNs) that regularly present developer profiles to their clients. These companies often need to refine contractors resumes correcting errors, and reformatting them to match the company&#8217;s branding and color scheme. </p><p>This process is tedious and time-consuming, so we built an automated tool to make it easier.</p><p>We started working on Pinock.io in mid&#8217; 2023, but by January 2024, we decided to stop. We weren&#8217;t aligned on the timeline anymore, and we had exhausted ourselves. So, January was still dedicated to this project, but that was the end of it.</p><p>No regrets, though. I learned a lot from the experience and took valuable lessons from it.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!bjAi!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0f8a1ceb-e81a-40be-b053-3a50cd0ab922_1280x800.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!bjAi!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0f8a1ceb-e81a-40be-b053-3a50cd0ab922_1280x800.png 424w, https://substackcdn.com/image/fetch/$s_!bjAi!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0f8a1ceb-e81a-40be-b053-3a50cd0ab922_1280x800.png 848w, https://substackcdn.com/image/fetch/$s_!bjAi!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0f8a1ceb-e81a-40be-b053-3a50cd0ab922_1280x800.png 1272w, https://substackcdn.com/image/fetch/$s_!bjAi!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0f8a1ceb-e81a-40be-b053-3a50cd0ab922_1280x800.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!bjAi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0f8a1ceb-e81a-40be-b053-3a50cd0ab922_1280x800.png" width="1280" height="800" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0f8a1ceb-e81a-40be-b053-3a50cd0ab922_1280x800.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:800,&quot;width&quot;:1280,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Pinock.io - Chrome Web Store&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Pinock.io - Chrome Web Store" title="Pinock.io - Chrome Web Store" srcset="https://substackcdn.com/image/fetch/$s_!bjAi!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0f8a1ceb-e81a-40be-b053-3a50cd0ab922_1280x800.png 424w, https://substackcdn.com/image/fetch/$s_!bjAi!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0f8a1ceb-e81a-40be-b053-3a50cd0ab922_1280x800.png 848w, https://substackcdn.com/image/fetch/$s_!bjAi!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0f8a1ceb-e81a-40be-b053-3a50cd0ab922_1280x800.png 1272w, https://substackcdn.com/image/fetch/$s_!bjAi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0f8a1ceb-e81a-40be-b053-3a50cd0ab922_1280x800.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><h2><strong>February &amp; Mars 2024</strong> : <em>blog.stuffandcode.com </em>(this blog)</h2><p>Over the years, I&#8217;ve created a few blogs. I&#8217;ve always liked sharing my knowledge and findings, and I&#8217;ve tried multiple times to keep a blog going. But that kind of work isn&#8217;t for me. Yeah, that&#8217;s ironic since I&#8217;m literally journaling on my blog right now.</p><p>The problem is, I get exhausted. I can&#8217;t keep up with being consistent.</p><p>So I ran a blog for two months, focusing on Python specifically performance issues, how to identify them, and how to solve them. It&#8217;s a topic I enjoy, and I wanted to create content in my mother tongue, French, since there are already amazing resources in English.</p><p>But I guess it was too niche. Python developers + performance issues + French readers&#8230; too narrow of an audience. </p><p>I eventually gave up because, why bother?</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!JqG6!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb859ccfc-cccc-4b97-8aa7-2feb81ac6c87_1051x1157.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!JqG6!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb859ccfc-cccc-4b97-8aa7-2feb81ac6c87_1051x1157.png 424w, https://substackcdn.com/image/fetch/$s_!JqG6!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb859ccfc-cccc-4b97-8aa7-2feb81ac6c87_1051x1157.png 848w, https://substackcdn.com/image/fetch/$s_!JqG6!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb859ccfc-cccc-4b97-8aa7-2feb81ac6c87_1051x1157.png 1272w, https://substackcdn.com/image/fetch/$s_!JqG6!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb859ccfc-cccc-4b97-8aa7-2feb81ac6c87_1051x1157.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!JqG6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb859ccfc-cccc-4b97-8aa7-2feb81ac6c87_1051x1157.png" width="1051" height="1157" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b859ccfc-cccc-4b97-8aa7-2feb81ac6c87_1051x1157.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1157,&quot;width&quot;:1051,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1427836,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://blog.stuffandcode.com/i/158872100?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb859ccfc-cccc-4b97-8aa7-2feb81ac6c87_1051x1157.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!JqG6!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb859ccfc-cccc-4b97-8aa7-2feb81ac6c87_1051x1157.png 424w, https://substackcdn.com/image/fetch/$s_!JqG6!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb859ccfc-cccc-4b97-8aa7-2feb81ac6c87_1051x1157.png 848w, https://substackcdn.com/image/fetch/$s_!JqG6!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb859ccfc-cccc-4b97-8aa7-2feb81ac6c87_1051x1157.png 1272w, https://substackcdn.com/image/fetch/$s_!JqG6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb859ccfc-cccc-4b97-8aa7-2feb81ac6c87_1051x1157.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p></p><h2><strong>March 2024:</strong> <em>Building a template for the next projects</em></h2><p>In March 2024, I came across a French entrepreneur who was launching SaaS projects at lightning speed. He really inspired me. He kept saying that you shouldn&#8217;t spend too much time on ideas, just build, launch, see if it works, and repeat.</p><p>Like most people, every time I built something, I wanted it to be perfect: beautiful UI, no bugs, scalable, fully tested. But doing that, you end up spending months instead of days or weeks. So I thought : </p><div class="pullquote"><p><em>I&#8217;ve been doing things the same way for years, and it never worked. Let&#8217;s try something different.</em></p><p>TK 2024</p></div><p>At first, it was hard. It felt messy. No tests? Come on bro&#8217;? </p><p>Some parts of my code looked awful and could&#8217;ve been refactored, but they worked, so why spend more time on something that would most likely never even be used? The first few weeks were rough. It didn&#8217;t feel natural.</p><p><strong>So I made a rule</strong>: from now on, my projects should take <strong>no more than two weeks to build</strong>. </p><p>So I&#8217;ve decided to take time to build an awesome template for my future projects. I&#8217;ve setup everything I need, here&#8217;s a glimpse of the tech&#8217; stack.</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Dq1h!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fadcf502a-63b5-4ba8-99a5-c5e2e3fe60e1_1428x1133.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Dq1h!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fadcf502a-63b5-4ba8-99a5-c5e2e3fe60e1_1428x1133.png 424w, https://substackcdn.com/image/fetch/$s_!Dq1h!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fadcf502a-63b5-4ba8-99a5-c5e2e3fe60e1_1428x1133.png 848w, https://substackcdn.com/image/fetch/$s_!Dq1h!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fadcf502a-63b5-4ba8-99a5-c5e2e3fe60e1_1428x1133.png 1272w, https://substackcdn.com/image/fetch/$s_!Dq1h!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fadcf502a-63b5-4ba8-99a5-c5e2e3fe60e1_1428x1133.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Dq1h!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fadcf502a-63b5-4ba8-99a5-c5e2e3fe60e1_1428x1133.png" width="1428" height="1133" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/adcf502a-63b5-4ba8-99a5-c5e2e3fe60e1_1428x1133.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1133,&quot;width&quot;:1428,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:148738,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://blog.stuffandcode.com/i/158872100?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fadcf502a-63b5-4ba8-99a5-c5e2e3fe60e1_1428x1133.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Dq1h!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fadcf502a-63b5-4ba8-99a5-c5e2e3fe60e1_1428x1133.png 424w, https://substackcdn.com/image/fetch/$s_!Dq1h!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fadcf502a-63b5-4ba8-99a5-c5e2e3fe60e1_1428x1133.png 848w, https://substackcdn.com/image/fetch/$s_!Dq1h!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fadcf502a-63b5-4ba8-99a5-c5e2e3fe60e1_1428x1133.png 1272w, https://substackcdn.com/image/fetch/$s_!Dq1h!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fadcf502a-63b5-4ba8-99a5-c5e2e3fe60e1_1428x1133.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>(I built this tool early 2025, it&#8217;s free to use, enjoy <a href="https://weuse.dev">https://weuse.dev</a>) </p><p>You can find out my board <strong><a href="https://weuse.dev/b/j4Z8zeK6">here</a>.</strong></p><p></p><p>I&#8217;ve setup all the sign up login logic, payments hooks, metrics, user management, monitoring, deployments &#8230;</p><p>All I need to do is fork it, rename the occurrences and get started. And to deploy, it literally takes me 10 minutes, 8 to setup de VPS and 2 to deploy with Docker Compose, and Docker Swarm if I need horizontal scaling.  </p><p></p><h2><strong>April 2024</strong> : <em>Interactive-Tailwind.com</em> </h2><p></p><p>Backend and deployment weren&#8217;t really an issue for me, but the frontend? That&#8217;s what took most of my time. I really didn&#8217;t like it. And I sucked at it. Everything I built looked terrible and took me way too long.</p><p>I tried Vue.js, React, plain JavaScript, TypeScript&#8230; but none of them clicked. Then I discovered Svelte. It had a small learning curve, but it suited me well, plain JS, no unnecessary complexity. It was a good starting point.</p><p>But the real monster was still ahead.</p><h3><strong>CSS.</strong></h3><p>I&#8217;ve always hated it. I never got the hang of it.</p><p>I tried multiple times, bought a few courses, watched online tutorials. I managed to do some things, but the effort never felt worth the result. So I decided to try something different.</p><h3><strong>Tailwind.</strong></h3><p>I liked the idea of not leaving my HTML, of not having to name my elements with class names&#8230; but in the end, it was still CSS. So, back to square one.</p><p>I looked for practical online exercises to learn Tailwind, but I couldn&#8217;t find anything that suited me. Then I remembered </p><p></p><div class="pullquote"><p><em>The best way to learn is to teach others.</em></p><p>TK 2024 (Again)</p></div><p>So there I was, building a course to learn Tailwind CSS from scratch, even though I had no knowledge of it myself.</p><p>The UI looked terrible, but the concept was cool. I showed a target design, and users had to write Tailwind code to match it and move on.</p><p></p><p>Two weeks passed. I integrated payments and launched on Product Hunt.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!HkJ0!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbb3300f-146a-468d-9d3e-8ac8f67c3b6c_1018x130.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!HkJ0!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbb3300f-146a-468d-9d3e-8ac8f67c3b6c_1018x130.png 424w, https://substackcdn.com/image/fetch/$s_!HkJ0!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbb3300f-146a-468d-9d3e-8ac8f67c3b6c_1018x130.png 848w, https://substackcdn.com/image/fetch/$s_!HkJ0!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbb3300f-146a-468d-9d3e-8ac8f67c3b6c_1018x130.png 1272w, https://substackcdn.com/image/fetch/$s_!HkJ0!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbb3300f-146a-468d-9d3e-8ac8f67c3b6c_1018x130.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!HkJ0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbb3300f-146a-468d-9d3e-8ac8f67c3b6c_1018x130.png" width="1018" height="130" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cbb3300f-146a-468d-9d3e-8ac8f67c3b6c_1018x130.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:130,&quot;width&quot;:1018,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:16243,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://blog.stuffandcode.com/i/158872100?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbb3300f-146a-468d-9d3e-8ac8f67c3b6c_1018x130.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!HkJ0!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbb3300f-146a-468d-9d3e-8ac8f67c3b6c_1018x130.png 424w, https://substackcdn.com/image/fetch/$s_!HkJ0!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbb3300f-146a-468d-9d3e-8ac8f67c3b6c_1018x130.png 848w, https://substackcdn.com/image/fetch/$s_!HkJ0!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbb3300f-146a-468d-9d3e-8ac8f67c3b6c_1018x130.png 1272w, https://substackcdn.com/image/fetch/$s_!HkJ0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbb3300f-146a-468d-9d3e-8ac8f67c3b6c_1018x130.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p></p><p>Yeah, pretty sad. But I did not care, I learned a lot, I saw the whole process and I was ready to go on the next one. And I managed to get it done under 2 weeks. Success.</p><p>P.S: Don&#8217;t be too sad, because actually, since then, <a href="https://interactive-tailwind.com/">https://interactive-tailwind.com</a> has become my most successful project. But it had a lot of revamping throughout the months. That&#8217;s for next time.</p><p>Here&#8217;s a sneak peek on how it looks like today : </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!MbYU!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93e637b3-6ff7-4e8d-a91e-edb1176a8a5a_865x1016.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!MbYU!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93e637b3-6ff7-4e8d-a91e-edb1176a8a5a_865x1016.png 424w, https://substackcdn.com/image/fetch/$s_!MbYU!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93e637b3-6ff7-4e8d-a91e-edb1176a8a5a_865x1016.png 848w, https://substackcdn.com/image/fetch/$s_!MbYU!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93e637b3-6ff7-4e8d-a91e-edb1176a8a5a_865x1016.png 1272w, https://substackcdn.com/image/fetch/$s_!MbYU!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93e637b3-6ff7-4e8d-a91e-edb1176a8a5a_865x1016.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!MbYU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93e637b3-6ff7-4e8d-a91e-edb1176a8a5a_865x1016.png" width="865" height="1016" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/93e637b3-6ff7-4e8d-a91e-edb1176a8a5a_865x1016.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1016,&quot;width&quot;:865,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:252356,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://blog.stuffandcode.com/i/158872100?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93e637b3-6ff7-4e8d-a91e-edb1176a8a5a_865x1016.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!MbYU!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93e637b3-6ff7-4e8d-a91e-edb1176a8a5a_865x1016.png 424w, https://substackcdn.com/image/fetch/$s_!MbYU!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93e637b3-6ff7-4e8d-a91e-edb1176a8a5a_865x1016.png 848w, https://substackcdn.com/image/fetch/$s_!MbYU!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93e637b3-6ff7-4e8d-a91e-edb1176a8a5a_865x1016.png 1272w, https://substackcdn.com/image/fetch/$s_!MbYU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93e637b3-6ff7-4e8d-a91e-edb1176a8a5a_865x1016.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p></p><h2><strong>May 2024 :</strong> <em>PushBeacon.com</em></h2><p><br>To collect payments, I went with LemonSqueezy instead of Stripe because they act as a Merchant of Record (MoR). Basically, they handle all the tax stuff for you, which is a lifesaver when selling internationally. Doing it yourself is a real pain.</p><p>The problem is, LemonSqueezy doesn&#8217;t have a mobile app. So I had no way of knowing when I got paid unless I kept checking my emails. And yeah, no way I was doing that.</p><p>I started looking for an easy way to send custom notifications to my phone. I didn&#8217;t want to set up a Discord or Slack bot, and I keep most notifications disabled to avoid distractions, so I needed something else.</p><p>Then I thought, why not just build a super simple mobile app whose only job is to receive notifications I send it? Sounds fun. So I opened PyCharm, set up React Native with Expo, and after some <em>bibidi bobbidi boo</em>, I had an app in two weeks.</p><p>Releasing it on the stores was a nightmare, especially on iOS. I also spent way too much time on the landing page because I wanted users to instantly get what it was about, try it out, and see how in just a few seconds and a simple HTTP request, they could send notifications to their phones, tablets, or smartwatches.</p><p>Then I launched it on Product Hunt : </p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!pd1l!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febd1c919-226b-40c7-ab9c-2294251b46ed_1022x122.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!pd1l!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febd1c919-226b-40c7-ab9c-2294251b46ed_1022x122.png 424w, https://substackcdn.com/image/fetch/$s_!pd1l!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febd1c919-226b-40c7-ab9c-2294251b46ed_1022x122.png 848w, https://substackcdn.com/image/fetch/$s_!pd1l!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febd1c919-226b-40c7-ab9c-2294251b46ed_1022x122.png 1272w, https://substackcdn.com/image/fetch/$s_!pd1l!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febd1c919-226b-40c7-ab9c-2294251b46ed_1022x122.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!pd1l!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febd1c919-226b-40c7-ab9c-2294251b46ed_1022x122.png" width="1022" height="122" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ebd1c919-226b-40c7-ab9c-2294251b46ed_1022x122.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:122,&quot;width&quot;:1022,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:15323,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://blog.stuffandcode.com/i/158872100?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febd1c919-226b-40c7-ab9c-2294251b46ed_1022x122.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!pd1l!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febd1c919-226b-40c7-ab9c-2294251b46ed_1022x122.png 424w, https://substackcdn.com/image/fetch/$s_!pd1l!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febd1c919-226b-40c7-ab9c-2294251b46ed_1022x122.png 848w, https://substackcdn.com/image/fetch/$s_!pd1l!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febd1c919-226b-40c7-ab9c-2294251b46ed_1022x122.png 1272w, https://substackcdn.com/image/fetch/$s_!pd1l!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febd1c919-226b-40c7-ab9c-2294251b46ed_1022x122.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p></p><p>Daaamn! That&#8217;s what I&#8217;m talking about! And the best part? I got my first two payments ever for this. It was a lifetime deal, 45&#8364; each. Not crazy money, I know, but that psychological barrier was gone. I finally made money from something I built.</p><p>A few people subscribed to the monthly plan too, but it didn&#8217;t take long before things went flat. Today, it&#8217;s mostly just me and some friends using it to set up custom alerts for our own tools. I don&#8217;t really plan on maintaining it, especially when Apple asks for 100 bucks a year just to keep the app live on the store.</p><p>So yeah, I&#8217;ll keep using it as long as it works, but I&#8217;m not putting any more dev time into it.</p><p></p><p><strong>Almost on Time... But Mobile is a Different Beast</strong></p><p>The initial goal was to ship it in two weeks, and honestly, we were almost there. The  app was up and running within that time. But mobile isn&#8217;t like pure web SaaS. Getting approved on the stores, dealing with app signing, waiting for Apple&#8217;s review it all adds extra delays. That alone stretched the timeline a bit more than expected.</p><p>It made me realize that launching a mobile app is a whole different game compared to a simple web product. Would I do it again? Maybe, not haha.</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!3M5X!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F656045ea-d6ad-47fb-b7eb-ec7b452d715c_805x971.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!3M5X!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F656045ea-d6ad-47fb-b7eb-ec7b452d715c_805x971.png 424w, https://substackcdn.com/image/fetch/$s_!3M5X!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F656045ea-d6ad-47fb-b7eb-ec7b452d715c_805x971.png 848w, https://substackcdn.com/image/fetch/$s_!3M5X!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F656045ea-d6ad-47fb-b7eb-ec7b452d715c_805x971.png 1272w, https://substackcdn.com/image/fetch/$s_!3M5X!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F656045ea-d6ad-47fb-b7eb-ec7b452d715c_805x971.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!3M5X!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F656045ea-d6ad-47fb-b7eb-ec7b452d715c_805x971.png" width="805" height="971" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/656045ea-d6ad-47fb-b7eb-ec7b452d715c_805x971.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:971,&quot;width&quot;:805,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:81014,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://blog.stuffandcode.com/i/158872100?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F656045ea-d6ad-47fb-b7eb-ec7b452d715c_805x971.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!3M5X!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F656045ea-d6ad-47fb-b7eb-ec7b452d715c_805x971.png 424w, https://substackcdn.com/image/fetch/$s_!3M5X!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F656045ea-d6ad-47fb-b7eb-ec7b452d715c_805x971.png 848w, https://substackcdn.com/image/fetch/$s_!3M5X!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F656045ea-d6ad-47fb-b7eb-ec7b452d715c_805x971.png 1272w, https://substackcdn.com/image/fetch/$s_!3M5X!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F656045ea-d6ad-47fb-b7eb-ec7b452d715c_805x971.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><h2><strong>May &amp; June 2024</strong>: <em>Make-Landing.com</em></h2><p>No time to lose. I realized I was spending way too much time building landing pages, and when you look at it, most people use the same kind of layouts anyway. So why not create a landing page generator?</p><p>I went on a deep dive, scrolling and scraping a ton of beautiful websites built with Tailwind. I broke them down into components, Hero sections, Pricing, About, and so on. </p><p>Then I made those components available in VueJS, React, Svelte, and plain JS, and added a button to shuffle and generate landing pages with different themes.</p><p>You could just keep hitting the button until you found the perfect layout. Once you were happy with the result, you had to pay to download the source files.</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!J13t!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e60fabf-e5b5-4307-8f6b-1e7b50d455fd_1213x600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!J13t!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e60fabf-e5b5-4307-8f6b-1e7b50d455fd_1213x600.png 424w, https://substackcdn.com/image/fetch/$s_!J13t!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e60fabf-e5b5-4307-8f6b-1e7b50d455fd_1213x600.png 848w, https://substackcdn.com/image/fetch/$s_!J13t!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e60fabf-e5b5-4307-8f6b-1e7b50d455fd_1213x600.png 1272w, https://substackcdn.com/image/fetch/$s_!J13t!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e60fabf-e5b5-4307-8f6b-1e7b50d455fd_1213x600.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!J13t!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e60fabf-e5b5-4307-8f6b-1e7b50d455fd_1213x600.png" width="1213" height="600" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0e60fabf-e5b5-4307-8f6b-1e7b50d455fd_1213x600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:600,&quot;width&quot;:1213,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:992837,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://blog.stuffandcode.com/i/158872100?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e60fabf-e5b5-4307-8f6b-1e7b50d455fd_1213x600.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!J13t!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e60fabf-e5b5-4307-8f6b-1e7b50d455fd_1213x600.png 424w, https://substackcdn.com/image/fetch/$s_!J13t!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e60fabf-e5b5-4307-8f6b-1e7b50d455fd_1213x600.png 848w, https://substackcdn.com/image/fetch/$s_!J13t!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e60fabf-e5b5-4307-8f6b-1e7b50d455fd_1213x600.png 1272w, https://substackcdn.com/image/fetch/$s_!J13t!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e60fabf-e5b5-4307-8f6b-1e7b50d455fd_1213x600.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Decided to launch on Product Hunt : </p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Q_0N!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F505f2665-38a1-492c-8628-008ca202ae0f_1026x128.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Q_0N!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F505f2665-38a1-492c-8628-008ca202ae0f_1026x128.png 424w, https://substackcdn.com/image/fetch/$s_!Q_0N!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F505f2665-38a1-492c-8628-008ca202ae0f_1026x128.png 848w, https://substackcdn.com/image/fetch/$s_!Q_0N!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F505f2665-38a1-492c-8628-008ca202ae0f_1026x128.png 1272w, https://substackcdn.com/image/fetch/$s_!Q_0N!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F505f2665-38a1-492c-8628-008ca202ae0f_1026x128.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Q_0N!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F505f2665-38a1-492c-8628-008ca202ae0f_1026x128.png" width="1026" height="128" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/505f2665-38a1-492c-8628-008ca202ae0f_1026x128.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:128,&quot;width&quot;:1026,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:14478,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://blog.stuffandcode.com/i/158872100?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F505f2665-38a1-492c-8628-008ca202ae0f_1026x128.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Q_0N!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F505f2665-38a1-492c-8628-008ca202ae0f_1026x128.png 424w, https://substackcdn.com/image/fetch/$s_!Q_0N!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F505f2665-38a1-492c-8628-008ca202ae0f_1026x128.png 848w, https://substackcdn.com/image/fetch/$s_!Q_0N!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F505f2665-38a1-492c-8628-008ca202ae0f_1026x128.png 1272w, https://substackcdn.com/image/fetch/$s_!Q_0N!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F505f2665-38a1-492c-8628-008ca202ae0f_1026x128.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p></p><p>Back to square one. This project has been taken down since, it showed no interested, but again, my frontend skills improved. </p><p></p><h2><strong>June 2024: </strong><em>Couldn&#8217;t code much</em> </h2><p>In June 2024, I had eye surgery on both eyes. For about two to three weeks, I couldn&#8217;t really focus on screens. I was seeing double, which made it almost impossible to get anything done. So yeah, coding wasn&#8217;t really an option that month, but I kept myself busy with other things.</p><p></p><h2><strong>July &amp; August 2024</strong> :  <em>Palantly.com</em></h2><p>This time, I broke my own rule. I was spending the summer at a friend&#8217;s place, so I wanted to enjoy it and take things slow.</p><p>As I started juggling multiple projects, I needed a way to track if everything was running smoothly. I had Plausible Analytics to monitor traffic on my websites, but I had no way of knowing if my backend services were actually working. Setting up backend analytics, with health checks, response times, and all that, is always a hassle. So I thought, why not build something simpler? </p><p>Like <em>waaay</em> simpler.</p><p>Something as easy as dropping a <code>&lt;script&gt;</code> tag on a website and that&#8217;s it. Just like Plausible, but instead of tracking page views, it would track API calls and display everything in a clean, visual way. Nice graphs showing which routes were hit the most, how long they took, response statuses&#8230; all at a glance.</p><p>It was an interesting project because I got to play with new technologies, like ClickHouse. I went with it because I read some Plausible blog posts where they mentioned that Postgres wasn&#8217;t ideal for this kind of workload long-term. A little pretentious to assume I&#8217;d hit the same scaling issues, but hey, why not do it right from the start?</p><p>I spent the summer working on it. The UI was clean, I spent a lot of time finding the right graphs, and everything was running smoothly. Whenever a user browsed one of my websites, it would track API calls, measure their response times, and periodically send the stats to my backend. It worked well.</p><p>The logo looked amazing (thanks TK), so I was all set to launch on Product Hunt.</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!v6FO!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69b9c7d2-588c-47ba-8040-4690a649d83b_1022x136.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!v6FO!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69b9c7d2-588c-47ba-8040-4690a649d83b_1022x136.png 424w, https://substackcdn.com/image/fetch/$s_!v6FO!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69b9c7d2-588c-47ba-8040-4690a649d83b_1022x136.png 848w, https://substackcdn.com/image/fetch/$s_!v6FO!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69b9c7d2-588c-47ba-8040-4690a649d83b_1022x136.png 1272w, https://substackcdn.com/image/fetch/$s_!v6FO!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69b9c7d2-588c-47ba-8040-4690a649d83b_1022x136.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!v6FO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69b9c7d2-588c-47ba-8040-4690a649d83b_1022x136.png" width="1022" height="136" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/69b9c7d2-588c-47ba-8040-4690a649d83b_1022x136.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:136,&quot;width&quot;:1022,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:17209,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://blog.stuffandcode.com/i/158872100?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69b9c7d2-588c-47ba-8040-4690a649d83b_1022x136.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!v6FO!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69b9c7d2-588c-47ba-8040-4690a649d83b_1022x136.png 424w, https://substackcdn.com/image/fetch/$s_!v6FO!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69b9c7d2-588c-47ba-8040-4690a649d83b_1022x136.png 848w, https://substackcdn.com/image/fetch/$s_!v6FO!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69b9c7d2-588c-47ba-8040-4690a649d83b_1022x136.png 1272w, https://substackcdn.com/image/fetch/$s_!v6FO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69b9c7d2-588c-47ba-8040-4690a649d83b_1022x136.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p></p><p>Damn, that&#8217;s harsh. But you know, as time goes by, more and more products are released on Product Hunt, there are a lot of competition, a lot of bots, so it&#8217;s hard to have visibility. I kept using this for myself, it was useful for me. But today, I discontinued it. But i&#8217;m proud of it. </p><div data-attrs="{&quot;url&quot;:&quot;https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F2cd8dfac-a619-43eb-a039-a93c294e599b%2Fb5f654e6-8fd4-41db-b59f-d7612e9c8e7d%2Fimage.png?table=block&amp;id=00b42890-2946-442e-8986-0ad06e1d35fc&amp;spaceId=2cd8dfac-a619-43eb-a039-a93c294e599b&amp;width=2000&amp;userId=4369ebaf-acf3-4660-91ec-98333c9fede0&amp;cache=v2&quot;}" data-component-name="AssetErrorToDOM"><picture><img src="/img/missing-image.png" height="455" width="728"></picture></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!unFS!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb16dcbd6-0e07-40aa-a9d5-9d73771e4d0c_2048x3046.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!unFS!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb16dcbd6-0e07-40aa-a9d5-9d73771e4d0c_2048x3046.png 424w, https://substackcdn.com/image/fetch/$s_!unFS!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb16dcbd6-0e07-40aa-a9d5-9d73771e4d0c_2048x3046.png 848w, https://substackcdn.com/image/fetch/$s_!unFS!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb16dcbd6-0e07-40aa-a9d5-9d73771e4d0c_2048x3046.png 1272w, https://substackcdn.com/image/fetch/$s_!unFS!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb16dcbd6-0e07-40aa-a9d5-9d73771e4d0c_2048x3046.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!unFS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb16dcbd6-0e07-40aa-a9d5-9d73771e4d0c_2048x3046.png" width="1456" height="2166" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b16dcbd6-0e07-40aa-a9d5-9d73771e4d0c_2048x3046.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:2166,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!unFS!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb16dcbd6-0e07-40aa-a9d5-9d73771e4d0c_2048x3046.png 424w, https://substackcdn.com/image/fetch/$s_!unFS!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb16dcbd6-0e07-40aa-a9d5-9d73771e4d0c_2048x3046.png 848w, https://substackcdn.com/image/fetch/$s_!unFS!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb16dcbd6-0e07-40aa-a9d5-9d73771e4d0c_2048x3046.png 1272w, https://substackcdn.com/image/fetch/$s_!unFS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb16dcbd6-0e07-40aa-a9d5-9d73771e4d0c_2048x3046.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><h2><strong>Wrapping Up &#8211; Part 1</strong></h2><p></p><p>So yeah, we&#8217;re only at August 2024, and there&#8217;s still a lot more to cover. But this gives you a sneak peek into what I&#8217;ve been up to these past months, just building, testing ideas, seeing what sticks, stopping, and repeating.</p><p>I won&#8217;t lie, it&#8217;s exhausting. I know I should take longer breaks sometimes to avoid burning out, but until I can actually make a living from these projects, I don&#8217;t really have that luxury. I know I&#8217;ll get there eventually, but it takes time, effort, perseverance&#8230; and a bit of luck.</p><p>Writing this down helps too.</p><p>Thanks for reading.</p><p></p><p>See you soon! &#129437;</p><p>TK.</p>]]></content:encoded></item><item><title><![CDATA[Symfoz - The return of the Feed]]></title><description><![CDATA[Yeah, it's happening !]]></description><link>https://blog.stuffandcode.com/p/symfoz-the-return-of-the-feed</link><guid isPermaLink="false">https://blog.stuffandcode.com/p/symfoz-the-return-of-the-feed</guid><dc:creator><![CDATA[Téva KRIEF]]></dc:creator><pubDate>Tue, 04 Feb 2025 18:47:57 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!rbhb!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd483144a-b9fc-491e-a330-12ce2f2a9b6c_2048x1184.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Do you remember <strong>Symfoz</strong> ? </p><p>If you&#8217;re an OG you remember this  &#11015;&#65039;</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!rbhb!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd483144a-b9fc-491e-a330-12ce2f2a9b6c_2048x1184.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!rbhb!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd483144a-b9fc-491e-a330-12ce2f2a9b6c_2048x1184.png 424w, https://substackcdn.com/image/fetch/$s_!rbhb!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd483144a-b9fc-491e-a330-12ce2f2a9b6c_2048x1184.png 848w, https://substackcdn.com/image/fetch/$s_!rbhb!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd483144a-b9fc-491e-a330-12ce2f2a9b6c_2048x1184.png 1272w, https://substackcdn.com/image/fetch/$s_!rbhb!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd483144a-b9fc-491e-a330-12ce2f2a9b6c_2048x1184.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!rbhb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd483144a-b9fc-491e-a330-12ce2f2a9b6c_2048x1184.png" width="1456" height="842" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d483144a-b9fc-491e-a330-12ce2f2a9b6c_2048x1184.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:842,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;w=2000 (2048&#215;1184)&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="w=2000 (2048&#215;1184)" title="w=2000 (2048&#215;1184)" srcset="https://substackcdn.com/image/fetch/$s_!rbhb!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd483144a-b9fc-491e-a330-12ce2f2a9b6c_2048x1184.png 424w, https://substackcdn.com/image/fetch/$s_!rbhb!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd483144a-b9fc-491e-a330-12ce2f2a9b6c_2048x1184.png 848w, https://substackcdn.com/image/fetch/$s_!rbhb!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd483144a-b9fc-491e-a330-12ce2f2a9b6c_2048x1184.png 1272w, https://substackcdn.com/image/fetch/$s_!rbhb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd483144a-b9fc-491e-a330-12ce2f2a9b6c_2048x1184.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>I made this a while ago, like 3 years maybe, to try out to build something for me.<br><br>But for the new comers, what&#8217;s Symfoz ?<br><br>Basically, it&#8217;s an RSS aggregator. Where you could create custom feeds (<strong>playlists</strong>) of content that you found interesting. Like resources about Python programming language &#128580; , or music, design etc&#8230; And everything is aggregated in this playlist, so you just have to check this.<br><br>You were able to add RSS feeds ofc, but also <strong>Youtube channels</strong>, <strong>Spotify shows,</strong> <strong>Twitter</strong> handles &#8230; And the best, you were able to share your playlist with other and follow other.</p><p></p><p>Anyhow, I was not good at frontend, the UX was not incredible, so I kept it online for my most loyal user (Hey mom &#128075;). </p><p>And decided to take it down a few months ago. <br><br>But I felt sad about this. </p><p><br>So I&#8217;ve decided to revamp this tool, to add new features, try out new libs, and improve. And the best part ? <strong>I want to take you with me in this adventure.</strong><br><br><br>See you soon !</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.stuffandcode.com/subscribe?&quot;,&quot;text&quot;:&quot;S'abonner&quot;,&quot;language&quot;:&quot;fr&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">If you don&#8217;t want to miss new articles, just subscribe to my newsletter !  Or just wait for Symfoz to come out!</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Tapez votre e-mail&#8230;" tabindex="-1"><input type="submit" class="button primary" value="S'abonner"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Switch to English]]></title><description><![CDATA[Sorry to my french speakers, but we're too few :/]]></description><link>https://blog.stuffandcode.com/p/switch-to-english</link><guid isPermaLink="false">https://blog.stuffandcode.com/p/switch-to-english</guid><dc:creator><![CDATA[Téva KRIEF]]></dc:creator><pubDate>Sat, 25 Jan 2025 20:50:14 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/023dbdfe-c2f2-4559-99ec-05e7a95ca6cc_1024x1024.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Yup, it&#8217;s me!</p><p>I&#8217;ve decided to pick up the blog where I left off. But when I reflected on what I&#8217;d done previously, I realized it was &#8220;too niche.&#8221; By that, I mean it was aimed at:</p><ul><li><p>French-speaking people</p></li><li><p>Python developers (mostly)</p></li><li><p>Those interested in improving performance</p></li><li><p>Readers of articles, blogs, or content about the subject</p></li></ul><p>No need to say the target audience was pretty narrow. So I&#8217;ve decided to work on these aspects, and the first decision is to switch to English.</p><p>Don&#8217;t worry, I&#8217;m not a native speaker, so I&#8217;ll keep the vocabulary simple to make things easy to follow.</p><p>I&#8217;m not entirely sure what I&#8217;m going to write about yet. Maybe I&#8217;ll document my journey building a SaaS, share examples of open-source contributions, or just post random stuff. I don&#8217;t know. I guess we&#8217;ll see.</p><p></p><p>Talk to you soon!</p>]]></content:encoded></item><item><title><![CDATA[Explosion de performance Python avec Rust]]></title><description><![CDATA[Int&#233;grer du Rust dans du Python, quelle dr&#244;le d'id&#233;e ! Est-ce worth ?]]></description><link>https://blog.stuffandcode.com/p/explosion-de-performance-python-avec</link><guid isPermaLink="false">https://blog.stuffandcode.com/p/explosion-de-performance-python-avec</guid><dc:creator><![CDATA[Téva KRIEF]]></dc:creator><pubDate>Tue, 26 Mar 2024 09:01:19 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!0t1V!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6e2da8a-0b8f-4ae6-a47d-7ca12913c895_1024x1024.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!0t1V!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6e2da8a-0b8f-4ae6-a47d-7ca12913c895_1024x1024.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!0t1V!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6e2da8a-0b8f-4ae6-a47d-7ca12913c895_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!0t1V!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6e2da8a-0b8f-4ae6-a47d-7ca12913c895_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!0t1V!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6e2da8a-0b8f-4ae6-a47d-7ca12913c895_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!0t1V!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6e2da8a-0b8f-4ae6-a47d-7ca12913c895_1024x1024.webp 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!0t1V!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6e2da8a-0b8f-4ae6-a47d-7ca12913c895_1024x1024.webp" width="1024" height="1024" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b6e2da8a-0b8f-4ae6-a47d-7ca12913c895_1024x1024.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1024,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Illustrate a concept where a Python snake wraps around and integrates Rust elements for enhancing performance. The scene should visually represent a Python application, symbolized by a large, vibrant Python snake, incorporating Rust's distinct features like the Rust logo and a recognizable Rustacean figure for optimizing specific performance bottlenecks. The Python snake should be seen actively engaging with these Rust elements, such as gears and code snippets, to signify the seamless incorporation of Rust into Python for performance improvements. This depiction should highlight the strategic use of Rust within a Python environment to address and enhance critical sections of the application, emphasizing the collaboration between the two programming languages through visual metaphors that clearly identify both Python's and Rust's contributions.&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Illustrate a concept where a Python snake wraps around and integrates Rust elements for enhancing performance. The scene should visually represent a Python application, symbolized by a large, vibrant Python snake, incorporating Rust's distinct features like the Rust logo and a recognizable Rustacean figure for optimizing specific performance bottlenecks. The Python snake should be seen actively engaging with these Rust elements, such as gears and code snippets, to signify the seamless incorporation of Rust into Python for performance improvements. This depiction should highlight the strategic use of Rust within a Python environment to address and enhance critical sections of the application, emphasizing the collaboration between the two programming languages through visual metaphors that clearly identify both Python's and Rust's contributions." title="Illustrate a concept where a Python snake wraps around and integrates Rust elements for enhancing performance. The scene should visually represent a Python application, symbolized by a large, vibrant Python snake, incorporating Rust's distinct features like the Rust logo and a recognizable Rustacean figure for optimizing specific performance bottlenecks. The Python snake should be seen actively engaging with these Rust elements, such as gears and code snippets, to signify the seamless incorporation of Rust into Python for performance improvements. This depiction should highlight the strategic use of Rust within a Python environment to address and enhance critical sections of the application, emphasizing the collaboration between the two programming languages through visual metaphors that clearly identify both Python's and Rust's contributions." srcset="https://substackcdn.com/image/fetch/$s_!0t1V!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6e2da8a-0b8f-4ae6-a47d-7ca12913c895_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!0t1V!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6e2da8a-0b8f-4ae6-a47d-7ca12913c895_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!0t1V!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6e2da8a-0b8f-4ae6-a47d-7ca12913c895_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!0t1V!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6e2da8a-0b8f-4ae6-a47d-7ca12913c895_1024x1024.webp 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>On entend souvent dire que Python est lent. </p><p>Mais entre nous, c'est plus nuanc&#233; que &#231;a. En optimisant le code, il est possible de faire des merveilles sans avoir &#224; dire adieu &#224; Python. </p><p>Bien s&#251;r, il est &#233;vident que les <strong>langages compil&#233;s</strong>, genre Rust, <strong>ont une longueur d'avance c&#244;t&#233; vitesse.</strong> Mais peu importe car Python peut embarquer ces langages tels que nous pouvons le voir dans des biblioth&#232;ques qui int&#232;grent du <strong>C</strong> ou du <strong>Rust</strong>, comme <strong>Numpy</strong> ou <strong>Pydantic v2</strong>.</p><p></p><p><em><strong>Disclaimer</strong> : J'ai commenc&#233; &#224; faire du Rust tr&#232;s r&#233;cemment, donc si j'ai rat&#233; des optimisations ou des bonnes pratiques, c'est normal.</em></p><p></p><h2>Notre challenge : Advent Of Code 2022</h2><p><br>Afin d&#8217;apprendre un nouveau langage, je trouve qu&#8217;il est pertinent de tenter de r&#233;soudre des probl&#232;mes concrets, et de monter en difficult&#233;. </p><p>Pour ce faire j&#8217;ai d&#233;cid&#233; de prendre le <strong>Advent Of Code de 2022</strong> et d&#8217;essayer de r&#233;soudre le challenge une premi&#232;re fois en full Python et une seconde fois en Python qui int&#232;gre du Rust afin de comparer les performances.</p><p>Pour plus de d&#233;tails sur le d&#233;fi, vous pouvez <a href="https://adventofcode.com/2022/day/1">cliquer ici</a>. </p><p>Je n&#8217;entrerai pas sp&#233;cialement dans les d&#233;tails techniques de la solution. Pour r&#233;sumer l&#8217;&#233;nonc&#233;, voici l&#8217;id&#233;e du challenge :</p><p>Nous avons une string contenant des calories pour diff&#233;rents elfes (univers de No&#235;l). Nous devons trouver quel elfe poss&#232;de le plus de calories. Le jeu de donn&#233;es ressemble &#224; ceci :</p><pre><code>1000
233

1000
1000
6000

400
... </code></pre><p>Dans ce cas l&#224;, c&#8217;est le deuxi&#232;me elfe qui poss&#232;de le plus de calories, avec 1000 + 1000 + 6 000 calories = 8 000.</p><p>Le r&#233;sultat attendu est donc 8 000.</p><p></p><h2>Notre impl&#233;mentation en Python </h2><p>Voil&#224;, c&#8217;est presque du one-line. Concr&#232;tement on it&#232;re sur chaque bloc repr&#233;sentant un elfe (les double &#8220;\n&#8221;), on prend chaque ligne que nous convertissons en entier puis les additionnons ensemble.<br>Enfin, nous ordonnons la liste de sommes afin d&#8217;avoir le plus grand nombre en premier . </p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Ilg4!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc0255b1-0b12-4e49-93c0-c410f8cc4acb_1488x372.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Ilg4!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc0255b1-0b12-4e49-93c0-c410f8cc4acb_1488x372.png 424w, https://substackcdn.com/image/fetch/$s_!Ilg4!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc0255b1-0b12-4e49-93c0-c410f8cc4acb_1488x372.png 848w, https://substackcdn.com/image/fetch/$s_!Ilg4!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc0255b1-0b12-4e49-93c0-c410f8cc4acb_1488x372.png 1272w, https://substackcdn.com/image/fetch/$s_!Ilg4!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc0255b1-0b12-4e49-93c0-c410f8cc4acb_1488x372.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Ilg4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc0255b1-0b12-4e49-93c0-c410f8cc4acb_1488x372.png" width="1456" height="364" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/bc0255b1-0b12-4e49-93c0-c410f8cc4acb_1488x372.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:364,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:60771,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!Ilg4!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc0255b1-0b12-4e49-93c0-c410f8cc4acb_1488x372.png 424w, https://substackcdn.com/image/fetch/$s_!Ilg4!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc0255b1-0b12-4e49-93c0-c410f8cc4acb_1488x372.png 848w, https://substackcdn.com/image/fetch/$s_!Ilg4!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc0255b1-0b12-4e49-93c0-c410f8cc4acb_1488x372.png 1272w, https://substackcdn.com/image/fetch/$s_!Ilg4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc0255b1-0b12-4e49-93c0-c410f8cc4acb_1488x372.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Tadaaaa ! Nous savons quel est le maximum de calories parmi ces elfes.</p><p></p><h2>R&#233;&#233;crire notre logique en Rust</h2><p>Et maintenant, place &#224; <strong>Rust</strong>. </p><p>On va utiliser une librairie appel&#233;e <strong><a href="https://github.com/mityax/rustimport">rustimport</a></strong>. Cet outil nous facilite la vie en compilant notre code Rust pour qu'il  puisse &#234;tre utilis&#233; dans notre script Python, gr&#226;ce &#224; <strong><a href="https://github.com/PyO3/pyo3">PyO3</a></strong>.</p><p></p><blockquote><p><em><a href="https://www.rust-lang.org/">Rust</a> bindings for <a href="https://www.python.org/">Python</a>, including tools for creating native Python extension modules. Running and interacting with Python code from a Rust binary is also supported.</em></p><p>Tir&#233; de <a href="https://github.com/PyO3/pyo3">https://github.com/PyO3/pyo3 </a></p></blockquote><p></p><p>Voici notre fichier <strong>aoc.rs</strong></p><p>Nous avons d&#233;fini une fonction &#8220;<strong>compute</strong>&#8221; qui prend en param&#232;tre du texte et qui r&#233;alise les m&#234;mes traitements que notre script Python pr&#233;c&#233;dent.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!0Mcr!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F268d237d-81c7-4944-a801-991aac6c704a_1120x780.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!0Mcr!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F268d237d-81c7-4944-a801-991aac6c704a_1120x780.png 424w, https://substackcdn.com/image/fetch/$s_!0Mcr!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F268d237d-81c7-4944-a801-991aac6c704a_1120x780.png 848w, https://substackcdn.com/image/fetch/$s_!0Mcr!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F268d237d-81c7-4944-a801-991aac6c704a_1120x780.png 1272w, https://substackcdn.com/image/fetch/$s_!0Mcr!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F268d237d-81c7-4944-a801-991aac6c704a_1120x780.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!0Mcr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F268d237d-81c7-4944-a801-991aac6c704a_1120x780.png" width="1120" height="780" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/268d237d-81c7-4944-a801-991aac6c704a_1120x780.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:780,&quot;width&quot;:1120,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:96743,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!0Mcr!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F268d237d-81c7-4944-a801-991aac6c704a_1120x780.png 424w, https://substackcdn.com/image/fetch/$s_!0Mcr!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F268d237d-81c7-4944-a801-991aac6c704a_1120x780.png 848w, https://substackcdn.com/image/fetch/$s_!0Mcr!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F268d237d-81c7-4944-a801-991aac6c704a_1120x780.png 1272w, https://substackcdn.com/image/fetch/$s_!0Mcr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F268d237d-81c7-4944-a801-991aac6c704a_1120x780.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"></figcaption></figure></div><p>Pour avoir plus de d&#233;tails sur la syntaxe ad&#233;quate afin d&#8217;utiliser votre script dans votre programme Python, je vous renvoie vers <strong><a href="https://pyo3.rs/v0.20.2/">la documentation</a></strong>.</p><p></p><p>Maintenant, voici &#224; quoi ressemble <strong>notre script Python</strong> qui utilise ce fichier <strong>aoc.rs</strong></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!iysv!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6afcc51-c9b1-4175-acb2-a089fcf0a0cc_982x446.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!iysv!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6afcc51-c9b1-4175-acb2-a089fcf0a0cc_982x446.png 424w, https://substackcdn.com/image/fetch/$s_!iysv!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6afcc51-c9b1-4175-acb2-a089fcf0a0cc_982x446.png 848w, https://substackcdn.com/image/fetch/$s_!iysv!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6afcc51-c9b1-4175-acb2-a089fcf0a0cc_982x446.png 1272w, https://substackcdn.com/image/fetch/$s_!iysv!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6afcc51-c9b1-4175-acb2-a089fcf0a0cc_982x446.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!iysv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6afcc51-c9b1-4175-acb2-a089fcf0a0cc_982x446.png" width="982" height="446" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f6afcc51-c9b1-4175-acb2-a089fcf0a0cc_982x446.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:446,&quot;width&quot;:982,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:54640,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!iysv!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6afcc51-c9b1-4175-acb2-a089fcf0a0cc_982x446.png 424w, https://substackcdn.com/image/fetch/$s_!iysv!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6afcc51-c9b1-4175-acb2-a089fcf0a0cc_982x446.png 848w, https://substackcdn.com/image/fetch/$s_!iysv!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6afcc51-c9b1-4175-acb2-a089fcf0a0cc_982x446.png 1272w, https://substackcdn.com/image/fetch/$s_!iysv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6afcc51-c9b1-4175-acb2-a089fcf0a0cc_982x446.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Vous pouvez voir que le tout premier import vient de <strong>rustimport</strong>. </p><p>Qu&#8217;est-ce que <strong>rustimport.import_hook</strong> ? </p><p>C&#8217;est une ligne de code qui va permettre de regarder dans notre dossier s&#8217;il y a des fichiers .rs, et de les compiler afin d&#8217;&#234;tre utilisables par Python.</p><p>Par exemple, nous avons un fichier <strong>aoc.rs</strong>, ce qui signifie que <strong>notre module Python s&#8217;appelle &#8220;aoc&#8221;</strong>. </p><p>Ensuite, nous pouvons appeler la m&#233;thode &#8220;<strong>compute</strong>&#8221; de <strong>aoc</strong> pour faire les calculs. </p><p></p><div><hr></div><p>Si vous appr&#233;ciez la newsletter <strong>StuffAndCode</strong>, vous pouvez vous inscrire afin de ne manquer aucun article ! </p><p>&#128013; Et recevez en PLUS, un <strong>article exclusif</strong> sur comment profiler n&#8217;importe quel type de code Python.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.stuffandcode.com/subscribe?&quot;,&quot;text&quot;:&quot;Abonnez-vous maintenant&quot;,&quot;action&quot;:null,&quot;class&quot;:&quot;button-wrapper&quot;}" data-component-name="ButtonCreateButton"><a class="button primary button-wrapper" href="https://blog.stuffandcode.com/subscribe?"><span>Abonnez-vous maintenant</span></a></p><div><hr></div><p></p><h2>Mesurons les performances</h2><p><br>Pour cette occasion, j&#8217;ai d&#233;cid&#233; de mesurer le temps d&#8217;execution des deux fonctions &#8220;main&#8221; de mes scripts. Ceci exclut<strong> le temps de compilation</strong> mais mesure uniquement le temps d&#8217;execution de notre fonction.</p><p><br>On recommence cette op&#233;ration 1 000 fois, on calcule <strong>la moyenne du speedup de Rust par rapport a Python</strong> et &#233;galement <strong>l&#8217;&#233;cart type</strong> pour voir si les r&#233;sultats sont proches. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!hxe2!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97ec2e02-00f7-4576-9117-eef09ee83965_1488x1042.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!hxe2!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97ec2e02-00f7-4576-9117-eef09ee83965_1488x1042.png 424w, https://substackcdn.com/image/fetch/$s_!hxe2!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97ec2e02-00f7-4576-9117-eef09ee83965_1488x1042.png 848w, https://substackcdn.com/image/fetch/$s_!hxe2!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97ec2e02-00f7-4576-9117-eef09ee83965_1488x1042.png 1272w, https://substackcdn.com/image/fetch/$s_!hxe2!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97ec2e02-00f7-4576-9117-eef09ee83965_1488x1042.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!hxe2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97ec2e02-00f7-4576-9117-eef09ee83965_1488x1042.png" width="1456" height="1020" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/97ec2e02-00f7-4576-9117-eef09ee83965_1488x1042.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1020,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:197344,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!hxe2!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97ec2e02-00f7-4576-9117-eef09ee83965_1488x1042.png 424w, https://substackcdn.com/image/fetch/$s_!hxe2!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97ec2e02-00f7-4576-9117-eef09ee83965_1488x1042.png 848w, https://substackcdn.com/image/fetch/$s_!hxe2!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97ec2e02-00f7-4576-9117-eef09ee83965_1488x1042.png 1272w, https://substackcdn.com/image/fetch/$s_!hxe2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97ec2e02-00f7-4576-9117-eef09ee83965_1488x1042.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>En lan&#231;ant notre comparatif nous avons ces r&#233;sultats l&#224; : </p><pre><code><code>Results :
Mean Speedup: 1.1833177238773642
Standard Deviation: 0.06543422441011415</code></code></pre><p></p><p><strong>WTF</strong> ? Rust est uniquement <strong>1.18 foi</strong>s plus rapide que Python ? </p><p>C&#8217;est &#233;tonnant, ne trouvez-vous pas ?</p><p>Et si ! Effectivement, il y un tips &#224; savoir, un pi&#232;ge &#224; &#233;viter. Lorsqu&#8217;on compile &#8220;normalement&#8221; notre script Rust, le compilateur va <strong>g&#233;n&#233;rer une version &#8220;Debug&#8221;</strong> de notre script, et <strong>non pas une version optimis&#233;e</strong> telle qu&#8217;elle serait en production. </p><p><br>Pour ce faire, <strong>il suffit d&#8217;ajouter une ligne</strong> dans notre script Python pour pr&#233;ciser que nous voulons activer le build optimis&#233;.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!CWh4!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff16f6eea-9d28-4f83-9fca-59e48cb7039c_1136x558.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!CWh4!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff16f6eea-9d28-4f83-9fca-59e48cb7039c_1136x558.png 424w, https://substackcdn.com/image/fetch/$s_!CWh4!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff16f6eea-9d28-4f83-9fca-59e48cb7039c_1136x558.png 848w, https://substackcdn.com/image/fetch/$s_!CWh4!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff16f6eea-9d28-4f83-9fca-59e48cb7039c_1136x558.png 1272w, https://substackcdn.com/image/fetch/$s_!CWh4!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff16f6eea-9d28-4f83-9fca-59e48cb7039c_1136x558.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!CWh4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff16f6eea-9d28-4f83-9fca-59e48cb7039c_1136x558.png" width="1136" height="558" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f16f6eea-9d28-4f83-9fca-59e48cb7039c_1136x558.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:558,&quot;width&quot;:1136,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:79369,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!CWh4!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff16f6eea-9d28-4f83-9fca-59e48cb7039c_1136x558.png 424w, https://substackcdn.com/image/fetch/$s_!CWh4!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff16f6eea-9d28-4f83-9fca-59e48cb7039c_1136x558.png 848w, https://substackcdn.com/image/fetch/$s_!CWh4!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff16f6eea-9d28-4f83-9fca-59e48cb7039c_1136x558.png 1272w, https://substackcdn.com/image/fetch/$s_!CWh4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff16f6eea-9d28-4f83-9fca-59e48cb7039c_1136x558.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>Et l&#224;, en relan&#231;ant la mesure du temps, nous obtenons des r&#233;sultats plus proches de ce qu&#8217;on esp&#233;rait. <strong>Un speedup de quasiment x10</strong>.</p><pre><code>Results :
Mean Speedup: 9.970547291038583
Standard Deviation: 0.44621048695561444</code></pre><p></p><h2>Aller plus loin</h2><p>Comme je l&#8217;ai mentionn&#233; au d&#233;but de cet article, je suis un d&#233;butant en Rust. Mais je suis s&#251;r qu&#8217;avec plus d&#8217;expertise, les gains seraient bien plus importants.</p><p>A titre d&#8217;exp&#233;rience, j&#8217;ai demand&#233; &#224; GPT de m&#8217;&#233;crire une version optimis&#233;e de mon code. En parall&#232;le, j&#8217;ai v&#233;rifi&#233; que les r&#233;sultats &#233;taient les m&#234;mes.</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!nj0-!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb820337a-5da0-4476-b90d-535c4505fccb_1300x1702.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!nj0-!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb820337a-5da0-4476-b90d-535c4505fccb_1300x1702.png 424w, https://substackcdn.com/image/fetch/$s_!nj0-!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb820337a-5da0-4476-b90d-535c4505fccb_1300x1702.png 848w, https://substackcdn.com/image/fetch/$s_!nj0-!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb820337a-5da0-4476-b90d-535c4505fccb_1300x1702.png 1272w, https://substackcdn.com/image/fetch/$s_!nj0-!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb820337a-5da0-4476-b90d-535c4505fccb_1300x1702.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!nj0-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb820337a-5da0-4476-b90d-535c4505fccb_1300x1702.png" width="1300" height="1702" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b820337a-5da0-4476-b90d-535c4505fccb_1300x1702.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1702,&quot;width&quot;:1300,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:245526,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!nj0-!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb820337a-5da0-4476-b90d-535c4505fccb_1300x1702.png 424w, https://substackcdn.com/image/fetch/$s_!nj0-!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb820337a-5da0-4476-b90d-535c4505fccb_1300x1702.png 848w, https://substackcdn.com/image/fetch/$s_!nj0-!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb820337a-5da0-4476-b90d-535c4505fccb_1300x1702.png 1272w, https://substackcdn.com/image/fetch/$s_!nj0-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb820337a-5da0-4476-b90d-535c4505fccb_1300x1702.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>J&#8217;ignore exactement ce qu&#8217;il se passe dans ce code, mais en l&#8217;executant nous obtenons les r&#233;sultats suivants : </p><pre><code>Results :
Mean Speedup: 21.137375292664284
Standard Deviation: 0.9441126168701539</code></pre><p>Notre script Rust est <strong>21x plus rapide</strong> que notre fonction Python originale ! C&#8217;est assez impressionant ! Nous avons <strong>plus que doubl&#233; les performances de notre version Rust initiale</strong>. </p><p></p><h2>Conclusions</h2><ol><li><p><strong>Int&#233;gration de fonctions Rust dans Python</strong> : Nous avons vu que l'int&#233;gration de fonctions Rust dans des programmes Python est plus accessible qu'il n'y para&#238;t. </p></li><li><p><strong>Gains de performance</strong> : L'utilisation de Rust peut offrir des avantages significatifs en termes de performance. </p><p>Ces gains de performance peuvent &#234;tre utilis&#233;s pour optimiser certaines parties d'applications Python, des bottlenecks.</p></li><li><p><strong>Ajout d'options pour optimiser la performance</strong> : En utilisant <strong>rustimport,</strong> il est essentiel d'ajouter certaines options sp&#233;cifiques telles que &#8220;<strong>compile_release_binaries</strong>&#8221; lors de vos tests, sinon les r&#233;sultats ne seront pas repr&#233;sentatifs du gain r&#233;el.</p></li></ol><p></p><p>Cependant, il est important de noter que <strong>rustimport </strong>est un outil pour <strong>faciliter le prototypage</strong>, et savoir rapidement si int&#233;grer Rust vous sera b&#233;n&#233;fique.</p><p><br>Si vous comptez r&#233;ellement utiliser du Rust dans votre codebase, vous devrez le <strong>packager plus proprement</strong>; de la m&#234;me mani&#232;re si vous souhaitez utiliser des 3rd party librairies Rust, vous devrez &#233;galement ajouter de la configuration. </p><p><br>ET tout cela sera l&#8217;occasion d&#8217;un prochain article ! </p><p></p><div><hr></div><p>Si vous appr&#233;ciez la newsletter <strong>StuffAndCode</strong>, vous pouvez vous inscrire afin de ne manquer aucun article ! </p><p>&#128013; Et recevez en PLUS, un <strong>article exclusif</strong> sur comment profiler n&#8217;importe quel type de code Python.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.stuffandcode.com/subscribe?&quot;,&quot;text&quot;:&quot;Abonnez-vous maintenant&quot;,&quot;action&quot;:null,&quot;class&quot;:&quot;button-wrapper&quot;}" data-component-name="ButtonCreateButton"><a class="button primary button-wrapper" href="https://blog.stuffandcode.com/subscribe?"><span>Abonnez-vous maintenant</span></a></p><div><hr></div>]]></content:encoded></item><item><title><![CDATA[Testez la robustesse de votre API avec Locust]]></title><description><![CDATA[Notre API fonctionne. Bien ! Mais tient-elle la charge ? C'est parti pour du load testing avec Locust !]]></description><link>https://blog.stuffandcode.com/p/testez-la-robustesse-de-votre-api</link><guid isPermaLink="false">https://blog.stuffandcode.com/p/testez-la-robustesse-de-votre-api</guid><dc:creator><![CDATA[Téva KRIEF]]></dc:creator><pubDate>Tue, 12 Mar 2024 09:00:24 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!ugV2!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F788befa0-5cbb-49d8-a32e-2e28141491c3_1024x1024.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ugV2!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F788befa0-5cbb-49d8-a32e-2e28141491c3_1024x1024.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ugV2!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F788befa0-5cbb-49d8-a32e-2e28141491c3_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!ugV2!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F788befa0-5cbb-49d8-a32e-2e28141491c3_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!ugV2!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F788befa0-5cbb-49d8-a32e-2e28141491c3_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!ugV2!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F788befa0-5cbb-49d8-a32e-2e28141491c3_1024x1024.webp 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ugV2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F788befa0-5cbb-49d8-a32e-2e28141491c3_1024x1024.webp" width="1024" height="1024" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/788befa0-5cbb-49d8-a32e-2e28141491c3_1024x1024.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1024,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;An illustration representing the concept of load testing in Python using the Locust library. The image should feature a stylized python snake wrapped around a computer server, symbolizing the stress test. The server should look robust and emit digital signals, indicating activity. The Locust library can be represented by a swarm of digital locusts surrounding the server, applying load to it. The background should be a digital landscape, representing a network or cyberspace. Include Python and Locust logos subtly in the composition.&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="An illustration representing the concept of load testing in Python using the Locust library. The image should feature a stylized python snake wrapped around a computer server, symbolizing the stress test. The server should look robust and emit digital signals, indicating activity. The Locust library can be represented by a swarm of digital locusts surrounding the server, applying load to it. The background should be a digital landscape, representing a network or cyberspace. Include Python and Locust logos subtly in the composition." title="An illustration representing the concept of load testing in Python using the Locust library. The image should feature a stylized python snake wrapped around a computer server, symbolizing the stress test. The server should look robust and emit digital signals, indicating activity. The Locust library can be represented by a swarm of digital locusts surrounding the server, applying load to it. The background should be a digital landscape, representing a network or cyberspace. Include Python and Locust logos subtly in the composition." srcset="https://substackcdn.com/image/fetch/$s_!ugV2!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F788befa0-5cbb-49d8-a32e-2e28141491c3_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!ugV2!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F788befa0-5cbb-49d8-a32e-2e28141491c3_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!ugV2!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F788befa0-5cbb-49d8-a32e-2e28141491c3_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!ugV2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F788befa0-5cbb-49d8-a32e-2e28141491c3_1024x1024.webp 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>Lorsque nous d&#233;veloppons des services destin&#233;s &#224; &#234;tre utilis&#233;s avec un certain volume, il est crucial de tester notre code. </p><p>Les tests unitaires, fonctionnels, d'int&#233;gration et end-to-end, sont souvent mis en place dans les projets. C&#8217;est tr&#232;s bien, mais nous pouvons aller encore plus loin afin d&#8217;&#234;tre plus serein.</p><p><strong>Le load testing</strong> (test de charge en fran&#231;ais).</p><p>L'id&#233;e est d'envoyer un grand nombre de requ&#234;tes &#224; notre service pour observer sa r&#233;action face &#224; la charge. </p><p>Cela inclut l'&#233;valuation de la capacit&#233; d'absorption de la charge, du changement des temps de r&#233;ponse, des &#233;ventuelles erreurs dans les r&#233;ponses, et des comportements inattendus.</p><p>Cela permet aussi de d&#233;terminer le nombre maximal d'utilisateurs simultan&#233;s, afin d'ajuster le sizing ou le nombre de nos machines (vertical scaling vs horizontal scaling). </p><p></p><p>De plus, ces tests fournissent des informations sur la <strong>latency</strong> (temps n&#233;cessaire pour compl&#233;ter une action) versus le <strong>throughput</strong> (nombre d'op&#233;rations par unit&#233; de temps).</p><p>Voici <strong>ce magnifique GIF</strong> que j&#8217;ai r&#233;alis&#233; avec la librairie <a href="https://github.com/motion-canvas/motion-canvas">Motion Canvas</a>. Il y a encore un peu de boulot mais voici une illustration de la diff&#233;rence entre <strong>Latency</strong> et <strong>Throughput</strong>.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!-LaN!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fad086e1e-9e84-4e15-a8f6-b7affa09cc26_1920x1080.gif" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!-LaN!,w_424,c_limit,f_webp,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fad086e1e-9e84-4e15-a8f6-b7affa09cc26_1920x1080.gif 424w, https://substackcdn.com/image/fetch/$s_!-LaN!,w_848,c_limit,f_webp,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fad086e1e-9e84-4e15-a8f6-b7affa09cc26_1920x1080.gif 848w, https://substackcdn.com/image/fetch/$s_!-LaN!,w_1272,c_limit,f_webp,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fad086e1e-9e84-4e15-a8f6-b7affa09cc26_1920x1080.gif 1272w, https://substackcdn.com/image/fetch/$s_!-LaN!,w_1456,c_limit,f_webp,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fad086e1e-9e84-4e15-a8f6-b7affa09cc26_1920x1080.gif 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!-LaN!,w_1456,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fad086e1e-9e84-4e15-a8f6-b7affa09cc26_1920x1080.gif" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ad086e1e-9e84-4e15-a8f6-b7affa09cc26_1920x1080.gif&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:10024545,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/gif&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!-LaN!,w_424,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fad086e1e-9e84-4e15-a8f6-b7affa09cc26_1920x1080.gif 424w, https://substackcdn.com/image/fetch/$s_!-LaN!,w_848,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fad086e1e-9e84-4e15-a8f6-b7affa09cc26_1920x1080.gif 848w, https://substackcdn.com/image/fetch/$s_!-LaN!,w_1272,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fad086e1e-9e84-4e15-a8f6-b7affa09cc26_1920x1080.gif 1272w, https://substackcdn.com/image/fetch/$s_!-LaN!,w_1456,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fad086e1e-9e84-4e15-a8f6-b7affa09cc26_1920x1080.gif 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!u1Mz!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F99e8e67a-9fc1-413f-99c9-bebab2f9b141_960x540.gif" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!u1Mz!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F99e8e67a-9fc1-413f-99c9-bebab2f9b141_960x540.gif 424w, https://substackcdn.com/image/fetch/$s_!u1Mz!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F99e8e67a-9fc1-413f-99c9-bebab2f9b141_960x540.gif 848w, https://substackcdn.com/image/fetch/$s_!u1Mz!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F99e8e67a-9fc1-413f-99c9-bebab2f9b141_960x540.gif 1272w, https://substackcdn.com/image/fetch/$s_!u1Mz!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F99e8e67a-9fc1-413f-99c9-bebab2f9b141_960x540.gif 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!u1Mz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F99e8e67a-9fc1-413f-99c9-bebab2f9b141_960x540.gif" width="960" height="540" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/99e8e67a-9fc1-413f-99c9-bebab2f9b141_960x540.gif&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:540,&quot;width&quot;:960,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:499530,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/gif&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!u1Mz!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F99e8e67a-9fc1-413f-99c9-bebab2f9b141_960x540.gif 424w, https://substackcdn.com/image/fetch/$s_!u1Mz!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F99e8e67a-9fc1-413f-99c9-bebab2f9b141_960x540.gif 848w, https://substackcdn.com/image/fetch/$s_!u1Mz!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F99e8e67a-9fc1-413f-99c9-bebab2f9b141_960x540.gif 1272w, https://substackcdn.com/image/fetch/$s_!u1Mz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F99e8e67a-9fc1-413f-99c9-bebab2f9b141_960x540.gif 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Z0sH!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13557316-08ae-4564-9c9d-a22225daa96b_1920x1080.gif" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Z0sH!,w_424,c_limit,f_webp,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13557316-08ae-4564-9c9d-a22225daa96b_1920x1080.gif 424w, https://substackcdn.com/image/fetch/$s_!Z0sH!,w_848,c_limit,f_webp,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13557316-08ae-4564-9c9d-a22225daa96b_1920x1080.gif 848w, https://substackcdn.com/image/fetch/$s_!Z0sH!,w_1272,c_limit,f_webp,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13557316-08ae-4564-9c9d-a22225daa96b_1920x1080.gif 1272w, https://substackcdn.com/image/fetch/$s_!Z0sH!,w_1456,c_limit,f_webp,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13557316-08ae-4564-9c9d-a22225daa96b_1920x1080.gif 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Z0sH!,w_1456,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13557316-08ae-4564-9c9d-a22225daa96b_1920x1080.gif" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/13557316-08ae-4564-9c9d-a22225daa96b_1920x1080.gif&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:20058866,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/gif&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Z0sH!,w_424,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13557316-08ae-4564-9c9d-a22225daa96b_1920x1080.gif 424w, https://substackcdn.com/image/fetch/$s_!Z0sH!,w_848,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13557316-08ae-4564-9c9d-a22225daa96b_1920x1080.gif 848w, https://substackcdn.com/image/fetch/$s_!Z0sH!,w_1272,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13557316-08ae-4564-9c9d-a22225daa96b_1920x1080.gif 1272w, https://substackcdn.com/image/fetch/$s_!Z0sH!,w_1456,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13557316-08ae-4564-9c9d-a22225daa96b_1920x1080.gif 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Je vais vous parler de la librairie <strong><a href="https://github.com/locustio/locust">Locust</a></strong>, une biblioth&#232;que Python permettant de faire du load testing en Python. <strong>Locust</strong> peut &#234;tre utilis&#233; via la <strong>ligne de commande</strong> ou une <strong>interface web</strong>.</p><p></p><p>&#10067;<em>Petit moment culture : Locust veut dire Sauterelle / Criquet pour rappeler les 10 plaies d&#8217;Egypte. L&#8217;id&#233;e sous-jacente est que Locust envahit notre API comme les sauterelles ont envahi l&#8217;Egypte tel que d&#233;crit dans <a href="https://fr.wikipedia.org/wiki/Livre_de_l%27Exode">le livre de l&#8217;Exode</a>.</em></p><p></p><p>Avec Locust, on d&#233;finit le <strong>nombre de connexions simultan&#233;es</strong> souhait&#233;es (par exemple, 1 000 pour simuler mille utilisateurs), et &#233;galement un "<strong>ramp-up</strong>" pour augmenter progressivement la charge. Si nous choisissons de tester 100 connexions simultann&#233;es avec un ramp-up de 10 utilisateurs, cela signifie que chaque seconde, nous ajoutons 10 utilisateurs pour monter progressivement la charge.</p><p> </p><p>Nous pouvons choisir les endpoints &#224; cibler et leur attribuer des poids relatifs. Locust permet &#233;galement de d&#233;finir un "<strong>wait_time</strong>" pour simuler de mani&#232;re plus r&#233;aliste le comportement d'un utilisateur, en introduisant des <strong>pauses entre les requ&#234;tes</strong>.</p><p></p><h2>Tester notre premi&#232;re API </h2><p>Sans plus attendre, voici un exemple. Nous avons une application FastAPI simple avec une seule route sur "/". Nous voulons &#233;valuer combien de requ&#234;tes peuvent &#234;tre g&#233;r&#233;es par cette application, sur mon ordinateur.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!M9gs!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa82e5f84-81ad-4464-937f-126a2d2fde7d_1636x484.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!M9gs!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa82e5f84-81ad-4464-937f-126a2d2fde7d_1636x484.png 424w, https://substackcdn.com/image/fetch/$s_!M9gs!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa82e5f84-81ad-4464-937f-126a2d2fde7d_1636x484.png 848w, https://substackcdn.com/image/fetch/$s_!M9gs!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa82e5f84-81ad-4464-937f-126a2d2fde7d_1636x484.png 1272w, https://substackcdn.com/image/fetch/$s_!M9gs!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa82e5f84-81ad-4464-937f-126a2d2fde7d_1636x484.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!M9gs!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa82e5f84-81ad-4464-937f-126a2d2fde7d_1636x484.png" width="1456" height="431" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a82e5f84-81ad-4464-937f-126a2d2fde7d_1636x484.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:431,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:61597,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!M9gs!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa82e5f84-81ad-4464-937f-126a2d2fde7d_1636x484.png 424w, https://substackcdn.com/image/fetch/$s_!M9gs!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa82e5f84-81ad-4464-937f-126a2d2fde7d_1636x484.png 848w, https://substackcdn.com/image/fetch/$s_!M9gs!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa82e5f84-81ad-4464-937f-126a2d2fde7d_1636x484.png 1272w, https://substackcdn.com/image/fetch/$s_!M9gs!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa82e5f84-81ad-4464-937f-126a2d2fde7d_1636x484.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Nous utilisons la commande suivante pour d&#233;marrer notre API : </p><pre><code>uvicorn app:app --workers 32</code></pre><p> J'ai choisi 32 workers car mon ordinateur a 32 c&#339;urs. </p><p>Apparemment, <a href="https://stackoverflow.com/questions/72374634/how-many-uvicorn-workers-do-i-have-to-have-in-production">la formule id&#233;ale</a> serait le nombre de CPU * 2 + 1, donc 65 dans mon cas.  Mais n&#8217;ayant pas constat&#233; de gain de performance, j&#8217;ai gard&#233; 32 workers. </p><p></p><div><hr></div><p>Si vous appr&#233;ciez la newsletter StuffAndCode, vous pouvez vous inscrire afin de ne manquer aucun article ! </p><p>&#128013; Et recevez en PLUS, un <strong>article exclusif</strong> sur comment profiler n&#8217;importe quel type de code Python.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.stuffandcode.com/subscribe?&quot;,&quot;text&quot;:&quot;Abonnez-vous maintenant&quot;,&quot;action&quot;:null,&quot;class&quot;:&quot;button-wrapper&quot;}" data-component-name="ButtonCreateButton"><a class="button primary button-wrapper" href="https://blog.stuffandcode.com/subscribe?"><span>Abonnez-vous maintenant</span></a></p><div><hr></div><p></p><p>Ensuite, &#233;crivons notre premier <strong>test de charge</strong> avec Locust. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!5NZE!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94687c28-0ef2-4b89-8cae-289767571ded_1636x446.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!5NZE!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94687c28-0ef2-4b89-8cae-289767571ded_1636x446.png 424w, https://substackcdn.com/image/fetch/$s_!5NZE!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94687c28-0ef2-4b89-8cae-289767571ded_1636x446.png 848w, https://substackcdn.com/image/fetch/$s_!5NZE!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94687c28-0ef2-4b89-8cae-289767571ded_1636x446.png 1272w, https://substackcdn.com/image/fetch/$s_!5NZE!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94687c28-0ef2-4b89-8cae-289767571ded_1636x446.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!5NZE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94687c28-0ef2-4b89-8cae-289767571ded_1636x446.png" width="1456" height="397" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/94687c28-0ef2-4b89-8cae-289767571ded_1636x446.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:397,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:71101,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!5NZE!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94687c28-0ef2-4b89-8cae-289767571ded_1636x446.png 424w, https://substackcdn.com/image/fetch/$s_!5NZE!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94687c28-0ef2-4b89-8cae-289767571ded_1636x446.png 848w, https://substackcdn.com/image/fetch/$s_!5NZE!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94687c28-0ef2-4b89-8cae-289767571ded_1636x446.png 1272w, https://substackcdn.com/image/fetch/$s_!5NZE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94687c28-0ef2-4b89-8cae-289767571ded_1636x446.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Nous cr&#233;ons une classe qui h&#233;rite de <code>HttpUser</code>, instanci&#233;e pour chaque utilisateur. </p><p>Par exemple, avec 1000 utilisateurs, cette classe sera instanci&#233;e 1000 fois.</p><p>Nous d&#233;finissons une seule t&#226;che avec le d&#233;corateur <code>@task</code>. </p><p>Si plusieurs t&#226;ches sont d&#233;finies, Locust les <strong>choisit al&#233;atoirement</strong>. Dans le test <code>test_home_page</code>, on utilise <code>self.client.get("/")</code>. </p><p>Pour <strong>sp&#233;cifier l&#8217;host</strong>, nous pouvons utiliser une <strong>variable d'environnement</strong> ou <strong>l'interface web</strong> de Locust. </p><p>Pour ce tutoriel, j'utilise l'interface web, parce que : why not ?</p><p>Apr&#232;s avoir &#233;crit notre test, d&#233;marrons Locust avec la commande :</p><pre><code><code>locust -f locustfile_part1.py --processes -1 --modern-ui</code></code></pre><ul><li><p>L'option -f pr&#233;cise le fichier &#224; ex&#233;cuter.</p></li><li><p>--processes -1 permet d'utiliser tous les processeurs disponibles sur notre machine pour envoyer le plus de requ&#234;tes possible</p></li><li><p> L'option --modern-ui utilise une interface web, plus sympa, qui est encore en beta</p></li></ul><p></p><p>Sur la page Locust, nous d&#233;finissons :</p><ul><li><p>le nombre d'utilisateurs &#224; simuler.</p></li><li><p> le ramp-up par seconde.</p></li><li><p>la dur&#233;e du test.</p><p></p></li></ul><p>Par exemple, nous pouvons monter &#224; 1000 utilisateurs, envoyer des requ&#234;tes pendant 30 secondes, puis arr&#234;ter, en sp&#233;cifiant ces param&#232;tres dans les champs appropri&#233;s.</p><p>Voici &#224; quoi ressemble l&#8217;&#233;cran de configuration de notre test de charge.</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!QVUq!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1ce7b92-6212-4abb-b736-f4363eb60e50_592x1019.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!QVUq!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1ce7b92-6212-4abb-b736-f4363eb60e50_592x1019.png 424w, https://substackcdn.com/image/fetch/$s_!QVUq!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1ce7b92-6212-4abb-b736-f4363eb60e50_592x1019.png 848w, https://substackcdn.com/image/fetch/$s_!QVUq!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1ce7b92-6212-4abb-b736-f4363eb60e50_592x1019.png 1272w, https://substackcdn.com/image/fetch/$s_!QVUq!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1ce7b92-6212-4abb-b736-f4363eb60e50_592x1019.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!QVUq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1ce7b92-6212-4abb-b736-f4363eb60e50_592x1019.png" width="382" height="657.5304054054054" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d1ce7b92-6212-4abb-b736-f4363eb60e50_592x1019.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1019,&quot;width&quot;:592,&quot;resizeWidth&quot;:382,&quot;bytes&quot;:54043,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!QVUq!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1ce7b92-6212-4abb-b736-f4363eb60e50_592x1019.png 424w, https://substackcdn.com/image/fetch/$s_!QVUq!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1ce7b92-6212-4abb-b736-f4363eb60e50_592x1019.png 848w, https://substackcdn.com/image/fetch/$s_!QVUq!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1ce7b92-6212-4abb-b736-f4363eb60e50_592x1019.png 1272w, https://substackcdn.com/image/fetch/$s_!QVUq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1ce7b92-6212-4abb-b736-f4363eb60e50_592x1019.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>J'ai configur&#233; le test pour &#233;valuer notre route avec 1 000 utilisateurs, sans sp&#233;cifier de d&#233;lai entre les requ&#234;tes. Ci-dessous, les r&#233;sultats.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Xc0O!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37da85b5-d45a-43cc-855b-ee9986256cd0_1624x611.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Xc0O!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37da85b5-d45a-43cc-855b-ee9986256cd0_1624x611.png 424w, https://substackcdn.com/image/fetch/$s_!Xc0O!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37da85b5-d45a-43cc-855b-ee9986256cd0_1624x611.png 848w, https://substackcdn.com/image/fetch/$s_!Xc0O!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37da85b5-d45a-43cc-855b-ee9986256cd0_1624x611.png 1272w, https://substackcdn.com/image/fetch/$s_!Xc0O!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37da85b5-d45a-43cc-855b-ee9986256cd0_1624x611.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Xc0O!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37da85b5-d45a-43cc-855b-ee9986256cd0_1624x611.png" width="1456" height="548" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/37da85b5-d45a-43cc-855b-ee9986256cd0_1624x611.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:548,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:106858,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Xc0O!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37da85b5-d45a-43cc-855b-ee9986256cd0_1624x611.png 424w, https://substackcdn.com/image/fetch/$s_!Xc0O!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37da85b5-d45a-43cc-855b-ee9986256cd0_1624x611.png 848w, https://substackcdn.com/image/fetch/$s_!Xc0O!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37da85b5-d45a-43cc-855b-ee9986256cd0_1624x611.png 1272w, https://substackcdn.com/image/fetch/$s_!Xc0O!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37da85b5-d45a-43cc-855b-ee9986256cd0_1624x611.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!XgPL!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7fd56995-fdb6-4639-b463-9794507a622f_1570x1355.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!XgPL!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7fd56995-fdb6-4639-b463-9794507a622f_1570x1355.png 424w, https://substackcdn.com/image/fetch/$s_!XgPL!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7fd56995-fdb6-4639-b463-9794507a622f_1570x1355.png 848w, https://substackcdn.com/image/fetch/$s_!XgPL!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7fd56995-fdb6-4639-b463-9794507a622f_1570x1355.png 1272w, https://substackcdn.com/image/fetch/$s_!XgPL!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7fd56995-fdb6-4639-b463-9794507a622f_1570x1355.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!XgPL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7fd56995-fdb6-4639-b463-9794507a622f_1570x1355.png" width="1456" height="1257" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7fd56995-fdb6-4639-b463-9794507a622f_1570x1355.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1257,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:210545,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!XgPL!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7fd56995-fdb6-4639-b463-9794507a622f_1570x1355.png 424w, https://substackcdn.com/image/fetch/$s_!XgPL!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7fd56995-fdb6-4639-b463-9794507a622f_1570x1355.png 848w, https://substackcdn.com/image/fetch/$s_!XgPL!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7fd56995-fdb6-4639-b463-9794507a622f_1570x1355.png 1272w, https://substackcdn.com/image/fetch/$s_!XgPL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7fd56995-fdb6-4639-b463-9794507a622f_1570x1355.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Les r&#233;sultats ne montrent <strong>aucune erreur</strong> sur nos routes, des <strong>temps de r&#233;ponse constants</strong>, et pour 1 000 utilisateurs simultan&#233;s, nous atteignons un peu plus de <strong>20 000 requ&#234;tes par seconde</strong>.</p><p>Vous pouvez consulter ces r&#233;sultats dans les tableaux ou graphiques, t&#233;l&#233;charger les donn&#233;es, consulter les logs, et voir le nombre de requ&#234;tes trait&#233;es par chaque worker.</p><p></p><p>Maintenant, passons &#224; quelque chose de plus concr&#234;t. </p><p></p><h2>Une API prot&#233;g&#233;e par du &#8220;JWT&#8221;</h2><p>Je vais simuler une API REST utilisant un JWT. Pour simplifier, je consid&#233;rerai qu'un header avec un Bearer token est valide pour l'authentification.</p><p>Voici le code de notre &#8220;API REST&#8221; :</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!vhQA!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa034628e-681b-43ba-bc9b-526047452dd2_1636x1302.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!vhQA!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa034628e-681b-43ba-bc9b-526047452dd2_1636x1302.png 424w, https://substackcdn.com/image/fetch/$s_!vhQA!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa034628e-681b-43ba-bc9b-526047452dd2_1636x1302.png 848w, https://substackcdn.com/image/fetch/$s_!vhQA!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa034628e-681b-43ba-bc9b-526047452dd2_1636x1302.png 1272w, https://substackcdn.com/image/fetch/$s_!vhQA!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa034628e-681b-43ba-bc9b-526047452dd2_1636x1302.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!vhQA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa034628e-681b-43ba-bc9b-526047452dd2_1636x1302.png" width="1456" height="1159" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a034628e-681b-43ba-bc9b-526047452dd2_1636x1302.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1159,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:223183,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!vhQA!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa034628e-681b-43ba-bc9b-526047452dd2_1636x1302.png 424w, https://substackcdn.com/image/fetch/$s_!vhQA!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa034628e-681b-43ba-bc9b-526047452dd2_1636x1302.png 848w, https://substackcdn.com/image/fetch/$s_!vhQA!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa034628e-681b-43ba-bc9b-526047452dd2_1636x1302.png 1272w, https://substackcdn.com/image/fetch/$s_!vhQA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa034628e-681b-43ba-bc9b-526047452dd2_1636x1302.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Nous disposons de trois routes :</p><ol><li><p>Le login qui renvoie un token.</p></li><li><p>Deux routes identiques simulant une ressource prot&#233;g&#233;e.</p></li></ol><p>Dans notre test Locust :</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!MlCJ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F060356b0-9128-45b1-8e0a-6013b8066a6c_1636x930.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!MlCJ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F060356b0-9128-45b1-8e0a-6013b8066a6c_1636x930.png 424w, https://substackcdn.com/image/fetch/$s_!MlCJ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F060356b0-9128-45b1-8e0a-6013b8066a6c_1636x930.png 848w, https://substackcdn.com/image/fetch/$s_!MlCJ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F060356b0-9128-45b1-8e0a-6013b8066a6c_1636x930.png 1272w, https://substackcdn.com/image/fetch/$s_!MlCJ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F060356b0-9128-45b1-8e0a-6013b8066a6c_1636x930.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!MlCJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F060356b0-9128-45b1-8e0a-6013b8066a6c_1636x930.png" width="1456" height="828" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/060356b0-9128-45b1-8e0a-6013b8066a6c_1636x930.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:828,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:191908,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!MlCJ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F060356b0-9128-45b1-8e0a-6013b8066a6c_1636x930.png 424w, https://substackcdn.com/image/fetch/$s_!MlCJ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F060356b0-9128-45b1-8e0a-6013b8066a6c_1636x930.png 848w, https://substackcdn.com/image/fetch/$s_!MlCJ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F060356b0-9128-45b1-8e0a-6013b8066a6c_1636x930.png 1272w, https://substackcdn.com/image/fetch/$s_!MlCJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F060356b0-9128-45b1-8e0a-6013b8066a6c_1636x930.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>La m&#233;thode <code>on_start</code> est utilis&#233;e pour d&#233;finir une action sp&#233;cifique au moment de la cr&#233;ation d'un nouvel utilisateur. Par exemple, chaque nouvel utilisateur envoie une requ&#234;te sur <code>/login</code> pour r&#233;cup&#233;rer un token, n&#233;cessaire pour s'authentifier sur les autres routes.</p><p>Nous avons ensuite <strong>deux autres t&#226;ches</strong> envoyant des requ&#234;tes sur les routes prot&#233;g&#233;es. Nous avons d&#233;cor&#233; notre deuxi&#232;me route avec  <code>@task(3)</code>. Cela nous sert &#224; donner <strong>un</strong> <strong>poids</strong>, c&#8217;est &#224; dire que cette route a <strong>trois fois plus de chances d'&#234;tre appel&#233;e</strong> que la premi&#232;re. Car pour rappel, Locust regarde toutes les m&#233;thodes d&#233;cor&#233;es de <code>@task</code> puis <strong>choisit de mani&#232;re random</strong>.</p><p>L'attribut <code>wait_time</code> de la classe d&#233;finit un <strong>intervalle al&#233;atoire</strong> entre 1 et 5 secondes entre chaque t&#226;che, afin de <strong>simuler un comportement utilisateur plus r&#233;aliste</strong>.</p><p></p><h2>Conclusion </h2><p>En conclusion, je voudrai souligner que Locust offre des possibilit&#233;s <strong>plus avanc&#233;es</strong> : </p><ul><li><p>envoyer des requ&#234;tes depuis plusieurs machines pour simuler <strong>des millions d&#8217;users</strong>.</p></li><li><p>Bien que nous ayons test&#233; une API REST dans cet article, Locust permet de tester <strong>plusieurs protocoles</strong> en utilisant diff&#233;rents clients. Plus d'informations sur ces clients sont disponibles <a href="https://github.com/SvenskaSpel/locust-plugins#users">ici</a>.</p></li></ul><p></p><p>Finalement, il est important de noter que j'ai ex&#233;cut&#233; le test de charge et l'API <strong>sur la m&#234;me machine par simplicit&#233;</strong>, mais cela a clairement influenc&#233; les r&#233;sultats. </p><p>Cela permet tout de m&#234;me de d&#233;tecter des bugs potentiels et d&#8217;avoir une vue globale. Pour pousser au maximum l&#8217;exp&#233;rience, il faudrait ex&#233;cuter le load testing sur une machine distincte.</p><p></p><div><hr></div><p>Si vous appr&#233;ciez la newsletter StuffAndCode, vous pouvez vous inscrire afin de ne manquer aucun article ! </p><p>&#128013; Et recevez en PLUS, un <strong>article exclusif</strong> sur comment profiler n&#8217;importe quel type de code Python.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.stuffandcode.com/subscribe?&quot;,&quot;text&quot;:&quot;Abonnez-vous maintenant&quot;,&quot;action&quot;:null,&quot;class&quot;:&quot;button-wrapper&quot;}" data-component-name="ButtonCreateButton"><a class="button primary button-wrapper" href="https://blog.stuffandcode.com/subscribe?"><span>Abonnez-vous maintenant</span></a></p><div><hr></div>]]></content:encoded></item><item><title><![CDATA[Accélérer nos tests Python avec la parallélisation]]></title><description><![CDATA[Pourquoi ? Comment ? Faut-il toujours paralleliser nos tests ?]]></description><link>https://blog.stuffandcode.com/p/accelerer-nos-tests-python-avec-de</link><guid isPermaLink="false">https://blog.stuffandcode.com/p/accelerer-nos-tests-python-avec-de</guid><dc:creator><![CDATA[Téva KRIEF]]></dc:creator><pubDate>Tue, 27 Feb 2024 09:00:39 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!i4hx!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F169b4886-a4ab-416f-899b-b83a72a7ea69_1024x1024.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!i4hx!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F169b4886-a4ab-416f-899b-b83a72a7ea69_1024x1024.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!i4hx!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F169b4886-a4ab-416f-899b-b83a72a7ea69_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!i4hx!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F169b4886-a4ab-416f-899b-b83a72a7ea69_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!i4hx!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F169b4886-a4ab-416f-899b-b83a72a7ea69_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!i4hx!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F169b4886-a4ab-416f-899b-b83a72a7ea69_1024x1024.webp 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!i4hx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F169b4886-a4ab-416f-899b-b83a72a7ea69_1024x1024.webp" width="1024" height="1024" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/169b4886-a4ab-416f-899b-b83a72a7ea69_1024x1024.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1024,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Create an image showcasing the concept of parallelization in Python programming with a clear emphasis on database interactions. Visualize a central Python programming language logo, with multiple parallel lines extending from it, each representing a thread of execution. These lines should branch off into stylized icons of databases and servers, indicating the connection and interaction with various data sources. The lines of parallel execution should be interconnected, forming a network that symbolizes efficient data processing and exchange. The background should be a digital landscape, filled with elements like circuit patterns, binary code, and digital waveforms, reflecting a sophisticated programming environment. The overall color scheme should incorporate Python's blue and yellow, creating a vibrant and modern look that highlights the theme of advanced computing in Python.&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Create an image showcasing the concept of parallelization in Python programming with a clear emphasis on database interactions. Visualize a central Python programming language logo, with multiple parallel lines extending from it, each representing a thread of execution. These lines should branch off into stylized icons of databases and servers, indicating the connection and interaction with various data sources. The lines of parallel execution should be interconnected, forming a network that symbolizes efficient data processing and exchange. The background should be a digital landscape, filled with elements like circuit patterns, binary code, and digital waveforms, reflecting a sophisticated programming environment. The overall color scheme should incorporate Python's blue and yellow, creating a vibrant and modern look that highlights the theme of advanced computing in Python." title="Create an image showcasing the concept of parallelization in Python programming with a clear emphasis on database interactions. Visualize a central Python programming language logo, with multiple parallel lines extending from it, each representing a thread of execution. These lines should branch off into stylized icons of databases and servers, indicating the connection and interaction with various data sources. The lines of parallel execution should be interconnected, forming a network that symbolizes efficient data processing and exchange. The background should be a digital landscape, filled with elements like circuit patterns, binary code, and digital waveforms, reflecting a sophisticated programming environment. The overall color scheme should incorporate Python's blue and yellow, creating a vibrant and modern look that highlights the theme of advanced computing in Python." srcset="https://substackcdn.com/image/fetch/$s_!i4hx!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F169b4886-a4ab-416f-899b-b83a72a7ea69_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!i4hx!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F169b4886-a4ab-416f-899b-b83a72a7ea69_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!i4hx!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F169b4886-a4ab-416f-899b-b83a72a7ea69_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!i4hx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F169b4886-a4ab-416f-899b-b83a72a7ea69_1024x1024.webp 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>Dans le d&#233;veloppement, la mise en place de tests est une &#233;tape incontournable. </p><p>Qu'ils soient unitaires, fonctionnels ou end-to-end, les tests garantissent la qualit&#233; et la fiabilit&#233; du code. Cependant, &#224; mesure que notre codebase s'&#233;largit, le nombre de tests augmente, entra&#238;nant une <strong>augmentation significative du temps de test</strong>. </p><p>Cette situation a <strong>deux cons&#233;quences</strong> principales : </p><ul><li><p>une perte de temps directe pour le d&#233;veloppeur. </p></li><li><p>dans le cas de pipelines de CI, des <strong>co&#251;ts accrus</strong> li&#233;s au temps d'ex&#233;cution des tests.</p></li></ul><p></p><p>&#9888;&#65039; Dans cet article, nous allons utiliser SQLlite en tant que base de donn&#233;es, mais cela fonctionne de la m&#234;me mani&#232;re si vous utilisez une autre base de donn&#233;es tels Postgres ou MySQL ou autre. <br>Il suffit de changer l&#8217;URL lors de la cr&#233;ation de l&#8217;engine SQLAlchemy. Par exemple :</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!mHmq!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3efb6712-23d9-4b90-bf32-04cdea49a0f1_1550x334.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!mHmq!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3efb6712-23d9-4b90-bf32-04cdea49a0f1_1550x334.png 424w, https://substackcdn.com/image/fetch/$s_!mHmq!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3efb6712-23d9-4b90-bf32-04cdea49a0f1_1550x334.png 848w, https://substackcdn.com/image/fetch/$s_!mHmq!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3efb6712-23d9-4b90-bf32-04cdea49a0f1_1550x334.png 1272w, https://substackcdn.com/image/fetch/$s_!mHmq!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3efb6712-23d9-4b90-bf32-04cdea49a0f1_1550x334.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!mHmq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3efb6712-23d9-4b90-bf32-04cdea49a0f1_1550x334.png" width="1456" height="314" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3efb6712-23d9-4b90-bf32-04cdea49a0f1_1550x334.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:314,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:62041,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!mHmq!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3efb6712-23d9-4b90-bf32-04cdea49a0f1_1550x334.png 424w, https://substackcdn.com/image/fetch/$s_!mHmq!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3efb6712-23d9-4b90-bf32-04cdea49a0f1_1550x334.png 848w, https://substackcdn.com/image/fetch/$s_!mHmq!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3efb6712-23d9-4b90-bf32-04cdea49a0f1_1550x334.png 1272w, https://substackcdn.com/image/fetch/$s_!mHmq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3efb6712-23d9-4b90-bf32-04cdea49a0f1_1550x334.png 1456w" sizes="100vw"></picture><div></div></div></a></figure></div><h2><strong>Acc&#233;l&#233;rer les tests</strong></h2><p>Plusieurs strat&#233;gies peuvent &#234;tre adopt&#233;es. </p><p>Par l'optimisation des tests eux-m&#234;mes, en observant ce qui prend du temps, peut-&#234;tre m&#234;me revoir le scope des fixtures etc&#8230; Mais cette approche a plusieurs limites, dont la premi&#232;re : si le code &#224; tester est long, malgr&#233; l&#8217;optimisation des tests, il y aura peu de diff&#233;rence.</p><p>La m&#233;thode la plus simple et la plus efficace semble &#234;tre la <strong>parall&#233;lisation des tests</strong>. L'id&#233;e est de lancer plusieurs tests simultan&#233;ment au lieu de les ex&#233;cuter les uns apr&#233;s les autres.</p><p></p><h2><strong>Parall&#233;lisation avec Pytest-xdist</strong></h2><p><a href="https://github.com/pytest-dev/pytest-xdist">Pytest-xdist</a> est un outil Python qui facilite cette parall&#233;lisation. L'utilisation de cet outil est simple : si vous disposez de 32 CPU, vous pouvez th&#233;oriquement ex&#233;cuter jusqu'&#224; 32 tests <strong>simultan&#233;ment</strong>. </p><p>Cette capacit&#233; &#224; ex&#233;cuter des tests en parall&#232;le peut grandement am&#233;liorer le temps n&#233;cessaire pour lancer votre suite de tests.</p><p>De plus, la mise en place est tr&#232;s facile : </p><pre><code>&gt;&gt; pip install pytest-xdist

&gt;&gt; pytest -n auto</code></pre><p>La commande <code>pytest -n auto </code>va d&#233;tecter automatiquement votre nombre de CPU afin de pouvoir cr&#233;er le nombre appropri&#233; de workers ,et d&#233;marrer les tests sur ceux-ci.</p><p></p><h2><strong>Les side-effects et la parall&#233;lisation</strong></h2><p>Cependant, la parall&#233;lisation soul&#232;ve un d&#233;fi de taille : la <strong>gestion des side effects</strong>. Certains tests peuvent modifier des ressources externes, comme des fichiers ou des bases de donn&#233;es, polluant ainsi les l&#8217;environnements pour d'autres tests. </p><p>Par exemple, un test cr&#233;ant des instances dans une base de donn&#233;es peut laisser des traces qui affecteront les tests suivants.</p><p>C&#8217;est un probl&#232;me connu : lorsqu&#8217;on execute des tests qui se servent d&#8217;une base de donn&#233;es, <strong>nous devons nettoyer cette base de donn&#233;es entre chaque test</strong>. </p><p></p><h2><strong>Nettoyer sa base de donn&#233;e apr&#232;s chaque test</strong></h2><p>Pour rem&#233;dier &#224; cela, deux approches principales sont souvent utilis&#233;es :  </p><ul><li><p>l'utilisation de <strong>rollbacks</strong> en fin de test </p></li><li><p>la <strong>suppression de la base de donn&#233;es</strong> apr&#232;s chaque test. </p><p></p></li></ul><p>Afin d&#8217;illustrer nos exemples, nous allons partir du model SQLAlchemy que nous d&#233;sirons tester : </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!2jIf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1b789a0-efac-4696-ad18-0b2d95f2c7b6_1450x856.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!2jIf!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1b789a0-efac-4696-ad18-0b2d95f2c7b6_1450x856.png 424w, https://substackcdn.com/image/fetch/$s_!2jIf!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1b789a0-efac-4696-ad18-0b2d95f2c7b6_1450x856.png 848w, https://substackcdn.com/image/fetch/$s_!2jIf!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1b789a0-efac-4696-ad18-0b2d95f2c7b6_1450x856.png 1272w, https://substackcdn.com/image/fetch/$s_!2jIf!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1b789a0-efac-4696-ad18-0b2d95f2c7b6_1450x856.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!2jIf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1b789a0-efac-4696-ad18-0b2d95f2c7b6_1450x856.png" width="1450" height="856" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d1b789a0-efac-4696-ad18-0b2d95f2c7b6_1450x856.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:856,&quot;width&quot;:1450,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:151456,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!2jIf!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1b789a0-efac-4696-ad18-0b2d95f2c7b6_1450x856.png 424w, https://substackcdn.com/image/fetch/$s_!2jIf!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1b789a0-efac-4696-ad18-0b2d95f2c7b6_1450x856.png 848w, https://substackcdn.com/image/fetch/$s_!2jIf!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1b789a0-efac-4696-ad18-0b2d95f2c7b6_1450x856.png 1272w, https://substackcdn.com/image/fetch/$s_!2jIf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1b789a0-efac-4696-ad18-0b2d95f2c7b6_1450x856.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><h3>1) Tests sans nettoyage des donn&#233;es</h3><p>Nous avons deux tests : un qui cr&#233;e un Book et qui v&#233;rifie qu&#8217;il existe bien un seul Book; un second test qui cr&#233;e 5 Books et qui v&#233;rifie qu&#8217;il en existe 5. Ces tests sont simples mais ils vont permettre d&#8217;illustrer nos propos.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!gj0d!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a35071d-c2c6-402a-9c7f-114ccbb560d1_1636x1414.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!gj0d!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a35071d-c2c6-402a-9c7f-114ccbb560d1_1636x1414.png 424w, https://substackcdn.com/image/fetch/$s_!gj0d!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a35071d-c2c6-402a-9c7f-114ccbb560d1_1636x1414.png 848w, https://substackcdn.com/image/fetch/$s_!gj0d!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a35071d-c2c6-402a-9c7f-114ccbb560d1_1636x1414.png 1272w, https://substackcdn.com/image/fetch/$s_!gj0d!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a35071d-c2c6-402a-9c7f-114ccbb560d1_1636x1414.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!gj0d!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a35071d-c2c6-402a-9c7f-114ccbb560d1_1636x1414.png" width="1456" height="1258" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4a35071d-c2c6-402a-9c7f-114ccbb560d1_1636x1414.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1258,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:289691,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!gj0d!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a35071d-c2c6-402a-9c7f-114ccbb560d1_1636x1414.png 424w, https://substackcdn.com/image/fetch/$s_!gj0d!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a35071d-c2c6-402a-9c7f-114ccbb560d1_1636x1414.png 848w, https://substackcdn.com/image/fetch/$s_!gj0d!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a35071d-c2c6-402a-9c7f-114ccbb560d1_1636x1414.png 1272w, https://substackcdn.com/image/fetch/$s_!gj0d!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a35071d-c2c6-402a-9c7f-114ccbb560d1_1636x1414.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"></figcaption></figure></div><p>Si j&#8217;execute de mani&#232;re s&#233;quentielle (l&#8217;un apr&#233;s l&#8217;autre) mes tests, je vais d&#8217;abord cr&#233;er 1 Book . Le test va passer. Mais lors du deuxieme test, je vais cr&#233;er 5 books suppl&#233;mentaires, sans avoir nettoy&#233; ma base de donn&#233;es, en supprimant le book de l&#8217;ancien test. Par cons&#233;quent, au lieu d&#8217;avoir 5 books j&#8217;en aurai 6. </p><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!-hqc!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e26753d-2750-4bfb-809b-382e389bf069_1256x538.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!-hqc!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e26753d-2750-4bfb-809b-382e389bf069_1256x538.png 424w, https://substackcdn.com/image/fetch/$s_!-hqc!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e26753d-2750-4bfb-809b-382e389bf069_1256x538.png 848w, https://substackcdn.com/image/fetch/$s_!-hqc!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e26753d-2750-4bfb-809b-382e389bf069_1256x538.png 1272w, https://substackcdn.com/image/fetch/$s_!-hqc!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e26753d-2750-4bfb-809b-382e389bf069_1256x538.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!-hqc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e26753d-2750-4bfb-809b-382e389bf069_1256x538.png" width="1256" height="538" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2e26753d-2750-4bfb-809b-382e389bf069_1256x538.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:538,&quot;width&quot;:1256,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:101091,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!-hqc!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e26753d-2750-4bfb-809b-382e389bf069_1256x538.png 424w, https://substackcdn.com/image/fetch/$s_!-hqc!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e26753d-2750-4bfb-809b-382e389bf069_1256x538.png 848w, https://substackcdn.com/image/fetch/$s_!-hqc!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e26753d-2750-4bfb-809b-382e389bf069_1256x538.png 1272w, https://substackcdn.com/image/fetch/$s_!-hqc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e26753d-2750-4bfb-809b-382e389bf069_1256x538.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Donc, il nous faut un moyen de remettre notre database en &#233;tat entre chaque test pour &#233;viter les pollutions.</p><p></p><h3>2.1) Utilisation de rollback &#224; la fin du test</h3><p>Afin d&#8217;&#233;viter la pollution de test, une solution souvent pr&#233;conis&#233;e est de r&#233;aliser un &#8220;rollback&#8221; &#224; la fin de notre test, de sorte que toutes les actions r&#233;alis&#233;es dans la transaction courante soient annul&#233;es. </p><p><br>On peut donc ajouter ce comportement directement &#224; notre fixture.</p><p>Essayons ce code ci : </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!V6ig!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5f903cfd-9c25-4520-b06c-eb741af6008c_2912x2186.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!V6ig!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5f903cfd-9c25-4520-b06c-eb741af6008c_2912x2186.png 424w, https://substackcdn.com/image/fetch/$s_!V6ig!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5f903cfd-9c25-4520-b06c-eb741af6008c_2912x2186.png 848w, https://substackcdn.com/image/fetch/$s_!V6ig!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5f903cfd-9c25-4520-b06c-eb741af6008c_2912x2186.png 1272w, https://substackcdn.com/image/fetch/$s_!V6ig!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5f903cfd-9c25-4520-b06c-eb741af6008c_2912x2186.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!V6ig!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5f903cfd-9c25-4520-b06c-eb741af6008c_2912x2186.png" width="1456" height="1093" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5f903cfd-9c25-4520-b06c-eb741af6008c_2912x2186.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1093,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1458217,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!V6ig!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5f903cfd-9c25-4520-b06c-eb741af6008c_2912x2186.png 424w, https://substackcdn.com/image/fetch/$s_!V6ig!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5f903cfd-9c25-4520-b06c-eb741af6008c_2912x2186.png 848w, https://substackcdn.com/image/fetch/$s_!V6ig!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5f903cfd-9c25-4520-b06c-eb741af6008c_2912x2186.png 1272w, https://substackcdn.com/image/fetch/$s_!V6ig!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5f903cfd-9c25-4520-b06c-eb741af6008c_2912x2186.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Voici les r&#233;sultats de ces tests :</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!XkIX!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6833dd86-f4c1-4122-91ce-c082e754791c_1259x491.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!XkIX!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6833dd86-f4c1-4122-91ce-c082e754791c_1259x491.png 424w, https://substackcdn.com/image/fetch/$s_!XkIX!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6833dd86-f4c1-4122-91ce-c082e754791c_1259x491.png 848w, https://substackcdn.com/image/fetch/$s_!XkIX!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6833dd86-f4c1-4122-91ce-c082e754791c_1259x491.png 1272w, https://substackcdn.com/image/fetch/$s_!XkIX!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6833dd86-f4c1-4122-91ce-c082e754791c_1259x491.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!XkIX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6833dd86-f4c1-4122-91ce-c082e754791c_1259x491.png" width="1259" height="491" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6833dd86-f4c1-4122-91ce-c082e754791c_1259x491.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:491,&quot;width&quot;:1259,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:97685,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!XkIX!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6833dd86-f4c1-4122-91ce-c082e754791c_1259x491.png 424w, https://substackcdn.com/image/fetch/$s_!XkIX!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6833dd86-f4c1-4122-91ce-c082e754791c_1259x491.png 848w, https://substackcdn.com/image/fetch/$s_!XkIX!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6833dd86-f4c1-4122-91ce-c082e754791c_1259x491.png 1272w, https://substackcdn.com/image/fetch/$s_!XkIX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6833dd86-f4c1-4122-91ce-c082e754791c_1259x491.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Comme vous pouvez le constater, les tests ne passent pas. Pourquoi ?</p><p>Tout simplement parce que, m&#234;me si nous faisons un &#8220;rollback&#8221; &#224; la fin du test dans notre test, apparaissent des commits pour seeder nos tests, et donc ces changements sont persist&#233;s en base de donn&#233;es au moment du commit.</p><p>Ainsi, d&#232;s que le test fait un commit, le rollback n&#8217;aura plus d&#8217;effet car les r&#233;sultats auront d&#233;j&#224; &#233;t&#233; persist&#233; en base de donn&#233;es.  </p><p></p><h2>2.2) Un hack pour rollback</h2><p>Il existe effectivement un &#8220;hack&#8221; pour rollback entre chaque test. </p><p>Mais ceci d&#233;passe le scope de cet article. Je vous renvoie &#224; l&#8217;article qui l&#8217;aborde en <a href="https://dev.to/jbrocher/fastapi-testing-a-database-5ao5">cliquant ici</a>. </p><p>Pour plus de d&#233;tails, vous pouvez directement vous rendre sur la page de SQLAlchemy qui d&#233;taille son fonctionnement en suivant <a href="https://docs.sqlalchemy.org/en/14/orm/session_transaction.html#joining-a-session-into-an-external-transaction-such-as-for-test-suites">ce lien</a>.</p><p></p><p>Si vous souhaitez simplement mettre en place le rollback dans vos tests, je vous transmets ci-dessous la fixture telle qu&#8217;elle est pr&#233;conis&#233;e dans l&#8217;article : </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!dH_e!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50667c44-806b-43c4-8385-1f834fde40c2_1636x670.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!dH_e!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50667c44-806b-43c4-8385-1f834fde40c2_1636x670.png 424w, https://substackcdn.com/image/fetch/$s_!dH_e!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50667c44-806b-43c4-8385-1f834fde40c2_1636x670.png 848w, https://substackcdn.com/image/fetch/$s_!dH_e!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50667c44-806b-43c4-8385-1f834fde40c2_1636x670.png 1272w, https://substackcdn.com/image/fetch/$s_!dH_e!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50667c44-806b-43c4-8385-1f834fde40c2_1636x670.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!dH_e!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50667c44-806b-43c4-8385-1f834fde40c2_1636x670.png" width="1456" height="596" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/50667c44-806b-43c4-8385-1f834fde40c2_1636x670.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:596,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:130158,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!dH_e!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50667c44-806b-43c4-8385-1f834fde40c2_1636x670.png 424w, https://substackcdn.com/image/fetch/$s_!dH_e!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50667c44-806b-43c4-8385-1f834fde40c2_1636x670.png 848w, https://substackcdn.com/image/fetch/$s_!dH_e!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50667c44-806b-43c4-8385-1f834fde40c2_1636x670.png 1272w, https://substackcdn.com/image/fetch/$s_!dH_e!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50667c44-806b-43c4-8385-1f834fde40c2_1636x670.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><div><hr></div><p>Si vous appr&#233;ciez la newsletter StuffAndCode, vous pouvez vous inscrire afin de ne manquer aucun article ! </p><p>&#128013; Et recevez en PLUS, un <strong>article exclusif</strong> sur comment profiler n&#8217;importe quel type de code Python.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.stuffandcode.com/subscribe?&quot;,&quot;text&quot;:&quot;Abonnez-vous maintenant&quot;,&quot;action&quot;:null,&quot;class&quot;:&quot;button-wrapper&quot;}" data-component-name="ButtonCreateButton"><a class="button primary button-wrapper" href="https://blog.stuffandcode.com/subscribe?"><span>Abonnez-vous maintenant</span></a></p><div><hr></div><p></p><h2>3) Drop la base de donn&#233;es</h2><p>Pourquoi ne pas tout simplement cr&#233;er et supprimer la base de donn&#233;es lors de chaque test ? Ca nous permettrait d&#8217;&#234;tre s&#251;r d&#8217;avoir un environnement propre ! </p><p>Nous pouvons mettre en place ce m&#233;canisme comme vous pouvez le voir ci-dessous.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!DriX!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf315aa6-e919-48ec-b04c-9f569bdf6495_2912x2848.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!DriX!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf315aa6-e919-48ec-b04c-9f569bdf6495_2912x2848.png 424w, https://substackcdn.com/image/fetch/$s_!DriX!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf315aa6-e919-48ec-b04c-9f569bdf6495_2912x2848.png 848w, https://substackcdn.com/image/fetch/$s_!DriX!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf315aa6-e919-48ec-b04c-9f569bdf6495_2912x2848.png 1272w, https://substackcdn.com/image/fetch/$s_!DriX!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf315aa6-e919-48ec-b04c-9f569bdf6495_2912x2848.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!DriX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf315aa6-e919-48ec-b04c-9f569bdf6495_2912x2848.png" width="1456" height="1424" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/bf315aa6-e919-48ec-b04c-9f569bdf6495_2912x2848.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1424,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1624345,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!DriX!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf315aa6-e919-48ec-b04c-9f569bdf6495_2912x2848.png 424w, https://substackcdn.com/image/fetch/$s_!DriX!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf315aa6-e919-48ec-b04c-9f569bdf6495_2912x2848.png 848w, https://substackcdn.com/image/fetch/$s_!DriX!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf315aa6-e919-48ec-b04c-9f569bdf6495_2912x2848.png 1272w, https://substackcdn.com/image/fetch/$s_!DriX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf315aa6-e919-48ec-b04c-9f569bdf6495_2912x2848.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!LoRB!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac21c531-875e-4d5f-b176-9c05b34a74c6_1253x202.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!LoRB!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac21c531-875e-4d5f-b176-9c05b34a74c6_1253x202.png 424w, https://substackcdn.com/image/fetch/$s_!LoRB!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac21c531-875e-4d5f-b176-9c05b34a74c6_1253x202.png 848w, https://substackcdn.com/image/fetch/$s_!LoRB!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac21c531-875e-4d5f-b176-9c05b34a74c6_1253x202.png 1272w, https://substackcdn.com/image/fetch/$s_!LoRB!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac21c531-875e-4d5f-b176-9c05b34a74c6_1253x202.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!LoRB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac21c531-875e-4d5f-b176-9c05b34a74c6_1253x202.png" width="1253" height="202" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ac21c531-875e-4d5f-b176-9c05b34a74c6_1253x202.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:202,&quot;width&quot;:1253,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:30155,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!LoRB!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac21c531-875e-4d5f-b176-9c05b34a74c6_1253x202.png 424w, https://substackcdn.com/image/fetch/$s_!LoRB!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac21c531-875e-4d5f-b176-9c05b34a74c6_1253x202.png 848w, https://substackcdn.com/image/fetch/$s_!LoRB!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac21c531-875e-4d5f-b176-9c05b34a74c6_1253x202.png 1272w, https://substackcdn.com/image/fetch/$s_!LoRB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac21c531-875e-4d5f-b176-9c05b34a74c6_1253x202.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Nos tests passent, c&#8217;est bien. Mais &#224; cette approche, incombent certains problemes.</p><p></p><h2>3.1) Les probl&#233;matiques de cette approche</h2><p>Supprimer et recr&#233;er la database pour chaque test prend du temps, et cela peut rallonger consid&#233;rablement le temps d&#8217;execution de vos tests.</p><p>Si vous parallelisez vos tests, cela veut &#233;galement dire que lorsqu&#8217;un test va terminer, il va modifier les donn&#233;es et polluer un autre test, &#233;galement drop la base de donn&#233;es, pendant que les autres tests finissent de s&#8217;executer. Ce qui va g&#233;n&#233;rer des erreurs:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Ou79!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56b9f339-7724-4df8-83cf-cb007849d098_1255x439.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Ou79!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56b9f339-7724-4df8-83cf-cb007849d098_1255x439.png 424w, https://substackcdn.com/image/fetch/$s_!Ou79!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56b9f339-7724-4df8-83cf-cb007849d098_1255x439.png 848w, https://substackcdn.com/image/fetch/$s_!Ou79!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56b9f339-7724-4df8-83cf-cb007849d098_1255x439.png 1272w, https://substackcdn.com/image/fetch/$s_!Ou79!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56b9f339-7724-4df8-83cf-cb007849d098_1255x439.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Ou79!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56b9f339-7724-4df8-83cf-cb007849d098_1255x439.png" width="1255" height="439" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/56b9f339-7724-4df8-83cf-cb007849d098_1255x439.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:439,&quot;width&quot;:1255,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:97125,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Ou79!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56b9f339-7724-4df8-83cf-cb007849d098_1255x439.png 424w, https://substackcdn.com/image/fetch/$s_!Ou79!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56b9f339-7724-4df8-83cf-cb007849d098_1255x439.png 848w, https://substackcdn.com/image/fetch/$s_!Ou79!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56b9f339-7724-4df8-83cf-cb007849d098_1255x439.png 1272w, https://substackcdn.com/image/fetch/$s_!Ou79!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56b9f339-7724-4df8-83cf-cb007849d098_1255x439.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><h2><strong>3.2) La Solution : Cr&#233;er une base de donn&#233;es par worker</strong></h2><p>Lors de l'utilisation de <a href="https://github.com/pytest-dev/pytest-xdist">Pytest-xdist</a>, un nouveau probl&#232;me &#233;merge : si chaque test parall&#233;lis&#233; tente de modifier la m&#234;me base de donn&#233;es, <strong>des conflits</strong> surviendront in&#233;vitablement. </p><p>La solution r&#233;side dans la modification de notre fixture de base de donn&#233;es pour cr&#233;er <strong>une base distincte pour chaque worker</strong>. Ainsi, chaque worker op&#232;re sur sa propre base de donn&#233;es, et &#233;vite les conflits tout en b&#233;n&#233;ficiant d<strong>'un v&#233;ritable parall&#233;lisme</strong>.</p><p>Pour ce faire, pytest-xdist ajoute une <strong>variable d&#8217;environnement</strong> &#8220;<code>PYTEST_XDIST_WORKER</code>&#8221; qui attribue une valeur pour chaque worker. Par exemple, si nous avons 10 workers, chaque worker aura une variable <code>PYTEST_XDIST_WORKER </code>qui vaudra 0, 1, 2 &#8230; 9.</p><p>Nous pouvons donc cr&#233;er une base de donn&#233;es pour chaque worker en nous servant  de cette variable d&#8217;environnement, r&#233;sultant en un environnement isol&#233; pour chaque worker. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!MzzW!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bcedac8-0074-4cb8-bfad-8a175c7369af_2912x2318.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!MzzW!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bcedac8-0074-4cb8-bfad-8a175c7369af_2912x2318.png 424w, https://substackcdn.com/image/fetch/$s_!MzzW!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bcedac8-0074-4cb8-bfad-8a175c7369af_2912x2318.png 848w, https://substackcdn.com/image/fetch/$s_!MzzW!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bcedac8-0074-4cb8-bfad-8a175c7369af_2912x2318.png 1272w, https://substackcdn.com/image/fetch/$s_!MzzW!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bcedac8-0074-4cb8-bfad-8a175c7369af_2912x2318.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!MzzW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bcedac8-0074-4cb8-bfad-8a175c7369af_2912x2318.png" width="1456" height="1159" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5bcedac8-0074-4cb8-bfad-8a175c7369af_2912x2318.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1159,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1226008,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!MzzW!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bcedac8-0074-4cb8-bfad-8a175c7369af_2912x2318.png 424w, https://substackcdn.com/image/fetch/$s_!MzzW!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bcedac8-0074-4cb8-bfad-8a175c7369af_2912x2318.png 848w, https://substackcdn.com/image/fetch/$s_!MzzW!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bcedac8-0074-4cb8-bfad-8a175c7369af_2912x2318.png 1272w, https://substackcdn.com/image/fetch/$s_!MzzW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bcedac8-0074-4cb8-bfad-8a175c7369af_2912x2318.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!T0GB!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36d7e6a5-5555-482f-b317-257f3c6491f0_1249x178.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!T0GB!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36d7e6a5-5555-482f-b317-257f3c6491f0_1249x178.png 424w, https://substackcdn.com/image/fetch/$s_!T0GB!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36d7e6a5-5555-482f-b317-257f3c6491f0_1249x178.png 848w, https://substackcdn.com/image/fetch/$s_!T0GB!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36d7e6a5-5555-482f-b317-257f3c6491f0_1249x178.png 1272w, https://substackcdn.com/image/fetch/$s_!T0GB!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36d7e6a5-5555-482f-b317-257f3c6491f0_1249x178.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!T0GB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36d7e6a5-5555-482f-b317-257f3c6491f0_1249x178.png" width="1249" height="178" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/36d7e6a5-5555-482f-b317-257f3c6491f0_1249x178.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:178,&quot;width&quot;:1249,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:30608,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!T0GB!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36d7e6a5-5555-482f-b317-257f3c6491f0_1249x178.png 424w, https://substackcdn.com/image/fetch/$s_!T0GB!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36d7e6a5-5555-482f-b317-257f3c6491f0_1249x178.png 848w, https://substackcdn.com/image/fetch/$s_!T0GB!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36d7e6a5-5555-482f-b317-257f3c6491f0_1249x178.png 1272w, https://substackcdn.com/image/fetch/$s_!T0GB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36d7e6a5-5555-482f-b317-257f3c6491f0_1249x178.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Cela fonctionne ! </p><p><br>Cependant, vous pouvez noter que le temps est tout de m&#234;me pass&#233; de +3s contre 0.23s pour la version s&#233;quentielle. La raison ? <strong>D&#233;marrer les tests sur plusieurs CPU prend du temp</strong>s !<br>Donc si vos tests sont d&#233;j&#224; tr&#233;s rapides de mani&#232;re s&#233;quentielle, il est peut-&#234;tre plus pertinent d&#8217;&#233;viter de mettre en place la parall&#233;lisation.</p><p>A l&#8217;inverse, si vos tests sont plus longs, le gain de temps peut-&#234;tre vraiment tr&#232;s int&#233;ressant.</p><p></p><h2>Quizz Time</h2><ul><li><p>Quelle librairie utilisons-nous pour paralleliser nos tests ?</p></li><li><p>Dans quel cas est-il pr&#233;f&#233;rable de ne pas paralleliser les tests ?</p></li><li><p>Quels sont les avantages et inconv&#233;nients de drop la database entre chaque test ?</p></li></ul><p></p><div><hr></div><p>Si vous appr&#233;ciez la newsletter StuffAndCode, vous pouvez vous inscrire afin de ne manquer aucun article ! </p><p>&#128013; Et recevez en PLUS, un <strong>article exclusif</strong> sur comment profiler n&#8217;importe quel type de code Python.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.stuffandcode.com/subscribe?&quot;,&quot;text&quot;:&quot;Abonnez-vous maintenant&quot;,&quot;action&quot;:null,&quot;class&quot;:&quot;button-wrapper&quot;}" data-component-name="ButtonCreateButton"><a class="button primary button-wrapper" href="https://blog.stuffandcode.com/subscribe?"><span>Abonnez-vous maintenant</span></a></p><div><hr></div>]]></content:encoded></item><item><title><![CDATA[Comment débugger un programme stuck en production]]></title><description><![CDATA[Apprenez &#224; trouver pourquoi votre service Python est bloqu&#233; sans avoir besoin de le red&#233;marrer !]]></description><link>https://blog.stuffandcode.com/p/comment-debugger-un-programme-stuck</link><guid isPermaLink="false">https://blog.stuffandcode.com/p/comment-debugger-un-programme-stuck</guid><dc:creator><![CDATA[Téva KRIEF]]></dc:creator><pubDate>Tue, 13 Feb 2024 09:01:12 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!SsaX!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1480bbf5-a177-49d6-be61-7e9e9a606346_1024x1024.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!SsaX!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1480bbf5-a177-49d6-be61-7e9e9a606346_1024x1024.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!SsaX!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1480bbf5-a177-49d6-be61-7e9e9a606346_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!SsaX!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1480bbf5-a177-49d6-be61-7e9e9a606346_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!SsaX!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1480bbf5-a177-49d6-be61-7e9e9a606346_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!SsaX!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1480bbf5-a177-49d6-be61-7e9e9a606346_1024x1024.webp 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!SsaX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1480bbf5-a177-49d6-be61-7e9e9a606346_1024x1024.webp" width="1024" height="1024" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1480bbf5-a177-49d6-be61-7e9e9a606346_1024x1024.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1024,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;A cartoon-style illustration showing a detective with a magnifying glass closely examining a Python program. The Python program is represented as a flowing stream of code, with the detective scrutinizing it for bugs or issues. The detective wears a classic detective hat and coat, and the magnifying glass prominently features the Python logo. The scene conveys a sense of investigation and analysis, highlighting the theme of debugging a program.&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="A cartoon-style illustration showing a detective with a magnifying glass closely examining a Python program. The Python program is represented as a flowing stream of code, with the detective scrutinizing it for bugs or issues. The detective wears a classic detective hat and coat, and the magnifying glass prominently features the Python logo. The scene conveys a sense of investigation and analysis, highlighting the theme of debugging a program." title="A cartoon-style illustration showing a detective with a magnifying glass closely examining a Python program. The Python program is represented as a flowing stream of code, with the detective scrutinizing it for bugs or issues. The detective wears a classic detective hat and coat, and the magnifying glass prominently features the Python logo. The scene conveys a sense of investigation and analysis, highlighting the theme of debugging a program." srcset="https://substackcdn.com/image/fetch/$s_!SsaX!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1480bbf5-a177-49d6-be61-7e9e9a606346_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!SsaX!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1480bbf5-a177-49d6-be61-7e9e9a606346_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!SsaX!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1480bbf5-a177-49d6-be61-7e9e9a606346_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!SsaX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1480bbf5-a177-49d6-be61-7e9e9a606346_1024x1024.webp 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>C&#8217;est une belle journ&#233;e d'&#233;t&#233;, tout est calme; un <strong>peu trop calme peut-&#234;tre</strong>. </p><p>Notre syst&#232;me de monitoring ne signale aucune erreur, alors que d'ordinaire, nous recevons quelques alertes Sentry par jour. Mais l&#224;, c'est <strong>silence radio</strong>, et c&#8217;est suspect.</p><p>En examinant nos donn&#233;es, nous nous rendons compte qu'il ne se passe rien depuis plusieurs heures. Pourtant, notre programme est configur&#233; pour red&#233;marrer automatiquement en cas de crash. </p><p>Nous nous pr&#233;cipitons sur la machine et ex&#233;cutons un <code>docker ps</code> pour v&#233;rifier si les conteneurs fonctionnent toujours. Oui, ils sont op&#233;rationnels. </p><p>Alors, que se passe-t-il ? Pourquoi l'activit&#233; semble-t-elle arr&#234;t&#233;e ? </p><p></p><p><strong>Let&#8217;s debug this sh*t. </strong></p><h2>Welcome to py-spy</h2><p></p><blockquote><p><em>py-spy is a sampling profiler for Python programs. It lets you visualize what your Python program is spending time on without restarting the program or modifying the code in any way. py-spy is extremely low overhead: it is written in Rust for speed and doesn't run in the same process as the profiled Python program. This means py-spy is safe to use against production Python code.</em></p><p>Tir&#233; de <a href="https://github.com/benfred/py-spy">https://github.com/benfred/py-spy</a></p></blockquote><p></p><h2>Les points fort de py-spy</h2><p>La librairie permet de r&#233;aliser plusieurs actions int&#233;ressantes :</p><ul><li><p><strong>Profiling de code</strong> : C'est un <a href="https://blog.stuffandcode.com/p/les-differents-types-de-profilers">statistical profiler</a>.</p></li><li><p><strong>Capacit&#233; &#224; se brancher directement</strong> sur un processus en cours d'ex&#233;cution sans n&#233;cessiter de modification du code, ou de red&#233;marrage de l'instance.</p></li><li><p><strong>Prise en charge du multiprocessing</strong> : Gestion efficace des environnements utilisant le multiprocessing, les workers gunicorn, etc&#8230;</p></li></ul><p></p><h1>Notre premier script &#224; debug</h1><p>Voici notre premier coupable : un script se retrouve stuck dans une boucle infinie et  qui ex&#233;cute <code>time.sleep </code>sans cesse.  </p><p>Nous allons ex&#233;cuter ce script sur <strong>notre host,</strong> et observer quelles informations &#233;mergent.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!cyoW!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd35db49e-144d-47ce-941d-876027f32c71_1608x1616.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!cyoW!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd35db49e-144d-47ce-941d-876027f32c71_1608x1616.png 424w, https://substackcdn.com/image/fetch/$s_!cyoW!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd35db49e-144d-47ce-941d-876027f32c71_1608x1616.png 848w, https://substackcdn.com/image/fetch/$s_!cyoW!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd35db49e-144d-47ce-941d-876027f32c71_1608x1616.png 1272w, https://substackcdn.com/image/fetch/$s_!cyoW!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd35db49e-144d-47ce-941d-876027f32c71_1608x1616.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!cyoW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd35db49e-144d-47ce-941d-876027f32c71_1608x1616.png" width="1456" height="1463" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d35db49e-144d-47ce-941d-876027f32c71_1608x1616.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1463,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:150848,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!cyoW!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd35db49e-144d-47ce-941d-876027f32c71_1608x1616.png 424w, https://substackcdn.com/image/fetch/$s_!cyoW!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd35db49e-144d-47ce-941d-876027f32c71_1608x1616.png 848w, https://substackcdn.com/image/fetch/$s_!cyoW!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd35db49e-144d-47ce-941d-876027f32c71_1608x1616.png 1272w, https://substackcdn.com/image/fetch/$s_!cyoW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd35db49e-144d-47ce-941d-876027f32c71_1608x1616.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Apr&#232;s l'avoir lanc&#233;, nous r&#233;cup&#233;rons le <strong>PID</strong> de notre processus, une information cruciale pour &#233;tablir la connexion avec <code>py-spy</code>.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!d_-8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febede1f8-987c-49d3-a01a-7a0d3e317619_1588x55.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!d_-8!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febede1f8-987c-49d3-a01a-7a0d3e317619_1588x55.png 424w, https://substackcdn.com/image/fetch/$s_!d_-8!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febede1f8-987c-49d3-a01a-7a0d3e317619_1588x55.png 848w, https://substackcdn.com/image/fetch/$s_!d_-8!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febede1f8-987c-49d3-a01a-7a0d3e317619_1588x55.png 1272w, https://substackcdn.com/image/fetch/$s_!d_-8!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febede1f8-987c-49d3-a01a-7a0d3e317619_1588x55.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!d_-8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febede1f8-987c-49d3-a01a-7a0d3e317619_1588x55.png" width="1456" height="50" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ebede1f8-987c-49d3-a01a-7a0d3e317619_1588x55.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:50,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:26974,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!d_-8!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febede1f8-987c-49d3-a01a-7a0d3e317619_1588x55.png 424w, https://substackcdn.com/image/fetch/$s_!d_-8!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febede1f8-987c-49d3-a01a-7a0d3e317619_1588x55.png 848w, https://substackcdn.com/image/fetch/$s_!d_-8!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febede1f8-987c-49d3-a01a-7a0d3e317619_1588x55.png 1272w, https://substackcdn.com/image/fetch/$s_!d_-8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febede1f8-987c-49d3-a01a-7a0d3e317619_1588x55.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption"></figcaption></figure></div><p><strong>py-spy</strong> offre actuellement <strong>trois commandes principales</strong> pour recueillir les informations sur notre processus. </p><p>Explorons-les !</p><h2>1) py-spy dump </h2><p><code>py-spy</code> offre la possibilit&#233; d'afficher la <strong>call stack</strong> actuelle de chaque thread Python avec la commande <code>dump</code>. </p><p>Nous avons &#233;galement la facult&#233; d&#8217;ajouter un flag &#8212;<code>locals</code> afin de voir les variables et leurs valeurs actuelles.</p><p></p><p><code>py-spy dump --pid 70300</code></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!1273!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea4a3870-0aea-4302-9038-2f0f7e919b93_809x156.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!1273!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea4a3870-0aea-4302-9038-2f0f7e919b93_809x156.png 424w, https://substackcdn.com/image/fetch/$s_!1273!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea4a3870-0aea-4302-9038-2f0f7e919b93_809x156.png 848w, https://substackcdn.com/image/fetch/$s_!1273!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea4a3870-0aea-4302-9038-2f0f7e919b93_809x156.png 1272w, https://substackcdn.com/image/fetch/$s_!1273!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea4a3870-0aea-4302-9038-2f0f7e919b93_809x156.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!1273!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea4a3870-0aea-4302-9038-2f0f7e919b93_809x156.png" width="809" height="156" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ea4a3870-0aea-4302-9038-2f0f7e919b93_809x156.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:156,&quot;width&quot;:809,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:26956,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!1273!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea4a3870-0aea-4302-9038-2f0f7e919b93_809x156.png 424w, https://substackcdn.com/image/fetch/$s_!1273!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea4a3870-0aea-4302-9038-2f0f7e919b93_809x156.png 848w, https://substackcdn.com/image/fetch/$s_!1273!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea4a3870-0aea-4302-9038-2f0f7e919b93_809x156.png 1272w, https://substackcdn.com/image/fetch/$s_!1273!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea4a3870-0aea-4302-9038-2f0f7e919b93_809x156.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Dans cet exemple, nous observons que le blocage se situe &#224; la ligne 7 et correspond effectivement &#224; notre instruction <code>time.sleep</code>. </p><p></p><h2>2) py-spy record </h2><p>Nous avons aussi la possibilit&#233; de nous connecter au processus, et de r&#233;aliser un <strong>enregistrement</strong> (record) sur une dur&#233;e plus &#233;tendue. </p><p>Lorsque nous estimons avoir collect&#233; suffisamment de donn&#233;es, un simple appui sur <code>Ctrl + C</code> interrompt le profiling. Cette action g&#233;n&#232;re un <strong>flamegraph</strong>, un visuel qui illustre o&#249; le code consacre la majorit&#233; de son temps d'ex&#233;cution.</p><p>Exemple de commande pour lancer le record :</p><p><code>py-spy record &#8212;pid 8773</code></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!h5ot!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d565638-c5f5-4ea0-9c54-fb59551f35b4_1078x263.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!h5ot!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d565638-c5f5-4ea0-9c54-fb59551f35b4_1078x263.png 424w, https://substackcdn.com/image/fetch/$s_!h5ot!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d565638-c5f5-4ea0-9c54-fb59551f35b4_1078x263.png 848w, https://substackcdn.com/image/fetch/$s_!h5ot!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d565638-c5f5-4ea0-9c54-fb59551f35b4_1078x263.png 1272w, https://substackcdn.com/image/fetch/$s_!h5ot!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d565638-c5f5-4ea0-9c54-fb59551f35b4_1078x263.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!h5ot!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d565638-c5f5-4ea0-9c54-fb59551f35b4_1078x263.png" width="1078" height="263" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2d565638-c5f5-4ea0-9c54-fb59551f35b4_1078x263.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:263,&quot;width&quot;:1078,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:22929,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!h5ot!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d565638-c5f5-4ea0-9c54-fb59551f35b4_1078x263.png 424w, https://substackcdn.com/image/fetch/$s_!h5ot!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d565638-c5f5-4ea0-9c54-fb59551f35b4_1078x263.png 848w, https://substackcdn.com/image/fetch/$s_!h5ot!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d565638-c5f5-4ea0-9c54-fb59551f35b4_1078x263.png 1272w, https://substackcdn.com/image/fetch/$s_!h5ot!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d565638-c5f5-4ea0-9c54-fb59551f35b4_1078x263.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Le flamegraph se lit de haut en bas. </p><p>Dans notre cas, il confirme effectivement que la ligne 7 ( notre fameux <code>time.sleep</code> ) monopolise le temps d'ex&#233;cution. Sans surprise !</p><p>Si vous le souhaitez ,vous pouvez visualiser ces r&#233;sultats autrement; avec un speedscope par exemple, le <a href="https://github.com/jlfwong/speedscope">lien est ici</a>. </p><p></p><div><hr></div><p>Si vous appr&#233;ciez la newsletter StuffAndCode, vous pouvez vous inscrire afin de ne manquer aucun article ! </p><p>&#128013; Et recevez en PLUS, un <strong>article exclusif</strong> sur comment profiler n&#8217;importe quel type de code Python.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.stuffandcode.com/subscribe?&quot;,&quot;text&quot;:&quot;Abonnez-vous maintenant&quot;,&quot;action&quot;:null,&quot;class&quot;:&quot;button-wrapper&quot;}" data-component-name="ButtonCreateButton"><a class="button primary button-wrapper" href="https://blog.stuffandcode.com/subscribe?"><span>Abonnez-vous maintenant</span></a></p><div><hr></div><p></p><h2>3) py-spy top</h2><p>py-spy propose la commande <code>top</code> afin de suivre le d&#233;roulement de notre programme. Nous pouvons lire les fonctions appel&#233;es, le temps d&#8217;execution etc &#8230; </p><p>Et c&#8217;est<strong> en temps r&#233;el</strong> ! Donc nul besoin d&#8217;&#234;tre &#224; l&#8217;aveugle comme sur la commande <code>record</code>, ou d&#8217;avoir juste un point dans le temps avec la commande <code>dump</code>. Ici nous visualisons directement ce qu&#8217;il se passe dans notre programme. </p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!y35f!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4be19340-a4ab-4be4-b9f4-55fac763fc5a_725x197.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!y35f!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4be19340-a4ab-4be4-b9f4-55fac763fc5a_725x197.png 424w, https://substackcdn.com/image/fetch/$s_!y35f!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4be19340-a4ab-4be4-b9f4-55fac763fc5a_725x197.png 848w, https://substackcdn.com/image/fetch/$s_!y35f!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4be19340-a4ab-4be4-b9f4-55fac763fc5a_725x197.png 1272w, https://substackcdn.com/image/fetch/$s_!y35f!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4be19340-a4ab-4be4-b9f4-55fac763fc5a_725x197.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!y35f!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4be19340-a4ab-4be4-b9f4-55fac763fc5a_725x197.png" width="725" height="197" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4be19340-a4ab-4be4-b9f4-55fac763fc5a_725x197.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:197,&quot;width&quot;:725,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:37581,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!y35f!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4be19340-a4ab-4be4-b9f4-55fac763fc5a_725x197.png 424w, https://substackcdn.com/image/fetch/$s_!y35f!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4be19340-a4ab-4be4-b9f4-55fac763fc5a_725x197.png 848w, https://substackcdn.com/image/fetch/$s_!y35f!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4be19340-a4ab-4be4-b9f4-55fac763fc5a_725x197.png 1272w, https://substackcdn.com/image/fetch/$s_!y35f!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4be19340-a4ab-4be4-b9f4-55fac763fc5a_725x197.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p></p><p>Cependant, nous pouvons constater que nous ne voyons pas exactement le num&#233;ro de la ligne execut&#233;e par le programme. </p><p></p><h1>Un cas concret </h1><p>Nous sommes en 2k24, nos services tournent dans des <strong>containers</strong> et le code est l&#233;g&#232;rement plus compliqu&#233; qu&#8217;une boucle while avec un sleep. On va essayer de randomiser tout cela afin de simuler une anomalie, sans qu&#8217;elle produise un blocage complet. </p><p></p><p>Nous allons ex&#233;cuter ce code dans un conteneur <strong>Docker</strong> utilisant Python 3.11, et rechercher o&#249; notre code consacre le plus de temps.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!GcXX!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F526bb9b5-1ff8-4def-a4d3-e89cbd8f6a11_1820x1976.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!GcXX!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F526bb9b5-1ff8-4def-a4d3-e89cbd8f6a11_1820x1976.png 424w, https://substackcdn.com/image/fetch/$s_!GcXX!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F526bb9b5-1ff8-4def-a4d3-e89cbd8f6a11_1820x1976.png 848w, https://substackcdn.com/image/fetch/$s_!GcXX!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F526bb9b5-1ff8-4def-a4d3-e89cbd8f6a11_1820x1976.png 1272w, https://substackcdn.com/image/fetch/$s_!GcXX!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F526bb9b5-1ff8-4def-a4d3-e89cbd8f6a11_1820x1976.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!GcXX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F526bb9b5-1ff8-4def-a4d3-e89cbd8f6a11_1820x1976.png" width="1456" height="1581" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/526bb9b5-1ff8-4def-a4d3-e89cbd8f6a11_1820x1976.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1581,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:290916,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!GcXX!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F526bb9b5-1ff8-4def-a4d3-e89cbd8f6a11_1820x1976.png 424w, https://substackcdn.com/image/fetch/$s_!GcXX!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F526bb9b5-1ff8-4def-a4d3-e89cbd8f6a11_1820x1976.png 848w, https://substackcdn.com/image/fetch/$s_!GcXX!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F526bb9b5-1ff8-4def-a4d3-e89cbd8f6a11_1820x1976.png 1272w, https://substackcdn.com/image/fetch/$s_!GcXX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F526bb9b5-1ff8-4def-a4d3-e89cbd8f6a11_1820x1976.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><h2>1) Debugger depuis l&#8217;host</h2><p>Notre code tourne dans un container <strong>Docker</strong>, mais rien ne nous emp&#234;che de le <strong>debugger depuis notre host</strong>. <br>Pour cela rien de plus simple. Nous cherchons le PID de notre processus Python qui tourne dans Docker, et nous lan&#231;ons les m&#234;mes commandes que nous avons vues pr&#233;cedemment. </p><p><br>Il est fort probable que vous deviez ex&#233;cuter la commande avec les <strong>droits</strong> <strong>root</strong> pour mener les observations.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Naqa!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20f64129-ea5e-4455-b1c6-6c6cdbce23eb_1806x651.gif" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Naqa!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20f64129-ea5e-4455-b1c6-6c6cdbce23eb_1806x651.gif 424w, https://substackcdn.com/image/fetch/$s_!Naqa!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20f64129-ea5e-4455-b1c6-6c6cdbce23eb_1806x651.gif 848w, https://substackcdn.com/image/fetch/$s_!Naqa!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20f64129-ea5e-4455-b1c6-6c6cdbce23eb_1806x651.gif 1272w, https://substackcdn.com/image/fetch/$s_!Naqa!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20f64129-ea5e-4455-b1c6-6c6cdbce23eb_1806x651.gif 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Naqa!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20f64129-ea5e-4455-b1c6-6c6cdbce23eb_1806x651.gif" width="1456" height="524" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/20f64129-ea5e-4455-b1c6-6c6cdbce23eb_1806x651.gif&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:524,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:146296,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/gif&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Naqa!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20f64129-ea5e-4455-b1c6-6c6cdbce23eb_1806x651.gif 424w, https://substackcdn.com/image/fetch/$s_!Naqa!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20f64129-ea5e-4455-b1c6-6c6cdbce23eb_1806x651.gif 848w, https://substackcdn.com/image/fetch/$s_!Naqa!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20f64129-ea5e-4455-b1c6-6c6cdbce23eb_1806x651.gif 1272w, https://substackcdn.com/image/fetch/$s_!Naqa!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20f64129-ea5e-4455-b1c6-6c6cdbce23eb_1806x651.gif 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>De la m&#234;me mani&#232;re, nous pouvons faire un <strong>record</strong> de programme, toujours pour mettre en &#233;vidence les actions, et analyser le flamegraph. </p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!5D5a!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec25d892-8074-4ad2-b929-90b8bad6cc60_1102x198.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!5D5a!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec25d892-8074-4ad2-b929-90b8bad6cc60_1102x198.png 424w, https://substackcdn.com/image/fetch/$s_!5D5a!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec25d892-8074-4ad2-b929-90b8bad6cc60_1102x198.png 848w, https://substackcdn.com/image/fetch/$s_!5D5a!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec25d892-8074-4ad2-b929-90b8bad6cc60_1102x198.png 1272w, https://substackcdn.com/image/fetch/$s_!5D5a!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec25d892-8074-4ad2-b929-90b8bad6cc60_1102x198.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!5D5a!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec25d892-8074-4ad2-b929-90b8bad6cc60_1102x198.png" width="1102" height="198" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ec25d892-8074-4ad2-b929-90b8bad6cc60_1102x198.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:198,&quot;width&quot;:1102,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:22231,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!5D5a!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec25d892-8074-4ad2-b929-90b8bad6cc60_1102x198.png 424w, https://substackcdn.com/image/fetch/$s_!5D5a!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec25d892-8074-4ad2-b929-90b8bad6cc60_1102x198.png 848w, https://substackcdn.com/image/fetch/$s_!5D5a!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec25d892-8074-4ad2-b929-90b8bad6cc60_1102x198.png 1272w, https://substackcdn.com/image/fetch/$s_!5D5a!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec25d892-8074-4ad2-b929-90b8bad6cc60_1102x198.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p></p><h2>2) Debugger depuis Docker</h2><p></p><p>Envisageons que vous ne <strong>vouliez/puissiez installer py-spy sur votre machine host </strong>de production. Peut-&#234;tre n&#8217;avez-vous pas de version Python compatible avec ? </p><p>Pas de soucis ! Nous pouvons debugger &#224; l&#8217;aide de <strong>Docker</strong>.</p><p></p><h3>Sc&#233;nario 1 : se servir du container de notre programme</h3><p><strong>Py-spy</strong> est reconnu pour &#234;tre <strong>low-overhead</strong>. Donc il aura un faible impact sur les performances de notre programme, et prendra peu de ressources de notre container. </p><p>Ainsi, nous pouvons imaginer ce sc&#233;nario : </p><ul><li><p>Entrer dans le container avec la commande <code>docker exec -ti &lt;container_name&gt; bash</code></p></li><li><p>Installer py-spy : <code>pip install py-spy</code></p></li><li><p>Trouver le PID de notre programme</p></li><li><p>Lancer le debug avec la commande <code>py-spy top</code> par exemple</p></li></ul><p></p><p>Nous avons un plan, testons le : </p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!8ygm!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64c3e700-a59f-49e5-95df-de81e1bd7009_547x75.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!8ygm!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64c3e700-a59f-49e5-95df-de81e1bd7009_547x75.png 424w, https://substackcdn.com/image/fetch/$s_!8ygm!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64c3e700-a59f-49e5-95df-de81e1bd7009_547x75.png 848w, https://substackcdn.com/image/fetch/$s_!8ygm!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64c3e700-a59f-49e5-95df-de81e1bd7009_547x75.png 1272w, https://substackcdn.com/image/fetch/$s_!8ygm!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64c3e700-a59f-49e5-95df-de81e1bd7009_547x75.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!8ygm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64c3e700-a59f-49e5-95df-de81e1bd7009_547x75.png" width="547" height="75" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/64c3e700-a59f-49e5-95df-de81e1bd7009_547x75.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:75,&quot;width&quot;:547,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:16016,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!8ygm!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64c3e700-a59f-49e5-95df-de81e1bd7009_547x75.png 424w, https://substackcdn.com/image/fetch/$s_!8ygm!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64c3e700-a59f-49e5-95df-de81e1bd7009_547x75.png 848w, https://substackcdn.com/image/fetch/$s_!8ygm!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64c3e700-a59f-49e5-95df-de81e1bd7009_547x75.png 1272w, https://substackcdn.com/image/fetch/$s_!8ygm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64c3e700-a59f-49e5-95df-de81e1bd7009_547x75.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p></p><p><strong>WTF ?</strong> Nous avons une &#8220;<strong>Operation not permitted</strong>&#8221; alors que nous sommes root ? </p><p></p><p><strong>py-spy</strong> offre de la documentation &#224; ce sujet que vous pouvez retrouver <a href="https://github.com/benfred/py-spy?tab=readme-ov-file#how-do-i-run-py-spy-in-docker">ici</a> .</p><p>On nous dit : </p><blockquote><p><em>Running py-spy inside of a docker container will also usually bring up a <strong>permissions denied error even when running as root.</strong></em></p><p><em>This error is caused by docker restricting the process_vm_readv system call we are using. This can be overridden by setting </em><code>--cap-add SYS_PTRACE</code><em><strong> </strong>when starting the docker container.</em></p><p><em>Alternatively you can edit the docker-compose yaml file</em></p><pre><code><code>your_service:
   cap_add:
     - SYS_PTRACE
</code></code></pre><p><em>Note that <strong>you'll need to restart the docker container</strong> in order for this setting to take effect.</em></p></blockquote><p></p><p>Donc, il est explicitement &#233;crit dit que si l&#8217;on d&#233;sire debugger notre programme dans <strong>Docker</strong>, il faut<strong> ajouter des capabilitie</strong>s et <strong>red&#233;marrer notre container</strong>. </p><p>Ce n&#8217;est vraiment pas incroyable, vu que potentiellement le bug se produit tr&#233;s rarement, et ignorons quand il va se reproduire. <br>Aussi, devoir faire des modifications de docker-compose juste pour &#231;ela, ce n&#8217;est pas fou. </p><p></p><p>&#10024;Soyez serein,<strong> nous avons une autre solution ! &#10024;</strong></p><p></p><h3>Sc&#233;nario 2: Debug depuis un autre container Docker</h3><p></p><p>Pourquoi pas <strong>d&#233;marrer un autre container</strong> en lui ajoutant la capability n&#233;cessaire pour profiler le code ? <br>Dans ce cas, nous devons partager le namespace du container que nous voulons debugger dans la commande afin que notre container de debug puisse cibler le processus &#224; debugger. <br><br>Nous pouvons utiliser la commande suivante :</p><p></p><p><code>docker run &nbsp;--cap-add=SYS_PTRACE &nbsp;--pid=container:&lt;container_name&gt; -it python:3.11 &nbsp;/bin/bash<br></code></p><p>Une fois a l&#8217;int&#233;rieur du container, il suffit d&#8217;installer <strong>py-spy</strong> et de lancer nos commandes.</p><p><code>py-spy top --pid 1</code></p><p></p><p>B<strong>ingo</strong> ! Nous voyons l&#8217;activit&#233; de notre autre container !</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!7Uhu!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6434687-4728-4bca-84fd-a80af92c8f77_706x249.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!7Uhu!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6434687-4728-4bca-84fd-a80af92c8f77_706x249.png 424w, https://substackcdn.com/image/fetch/$s_!7Uhu!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6434687-4728-4bca-84fd-a80af92c8f77_706x249.png 848w, https://substackcdn.com/image/fetch/$s_!7Uhu!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6434687-4728-4bca-84fd-a80af92c8f77_706x249.png 1272w, https://substackcdn.com/image/fetch/$s_!7Uhu!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6434687-4728-4bca-84fd-a80af92c8f77_706x249.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!7Uhu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6434687-4728-4bca-84fd-a80af92c8f77_706x249.png" width="706" height="249" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d6434687-4728-4bca-84fd-a80af92c8f77_706x249.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:249,&quot;width&quot;:706,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:47066,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!7Uhu!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6434687-4728-4bca-84fd-a80af92c8f77_706x249.png 424w, https://substackcdn.com/image/fetch/$s_!7Uhu!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6434687-4728-4bca-84fd-a80af92c8f77_706x249.png 848w, https://substackcdn.com/image/fetch/$s_!7Uhu!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6434687-4728-4bca-84fd-a80af92c8f77_706x249.png 1272w, https://substackcdn.com/image/fetch/$s_!7Uhu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6434687-4728-4bca-84fd-a80af92c8f77_706x249.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><h1>Choses &#224; noter : </h1><ul><li><p><strong>Limitation de Version Python</strong> : Actuellement, il est impossible de debug des programmes Python avec une version sup&#233;rieure &#224; 3.11 en utilisant <code>py-spy</code>, car il ne supporte pas encore ces versions.</p><p></p></li><li><p><strong>Fonctionnalit&#233;s &#201;tendues de py-spy</strong> : Les capacit&#233;s de <code>py-spy</code> vont bien au-del&#224; de ce qui a &#233;t&#233; pr&#233;sent&#233; ici. L'outil offre une multitude d'options pour le debug, notamment la prise en charge du multiprocessing, la possibilit&#233; de trier les instructions qui retiennent le Global Interpreter Lock (GIL), ainsi que l'observation des processus IDLE.</p><p></p></li><li><p><strong>Interpr&#233;tation des R&#233;sultats</strong> : en plus de flamegraph, <code>py-spy</code> propose &#233;galement d'autres visualisations et outils d'analyse.</p></li></ul><p></p><div><hr></div><p>Si vous appr&#233;ciez la newsletter StuffAndCode, vous pouvez vous inscrire afin de ne manquer aucun article ! </p><p>&#128013; Et recevez en PLUS, un <strong>article exclusif</strong> sur comment profiler n&#8217;importe quel type de code Python.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.stuffandcode.com/subscribe?&quot;,&quot;text&quot;:&quot;Abonnez-vous maintenant&quot;,&quot;action&quot;:null,&quot;class&quot;:&quot;button-wrapper&quot;}" data-component-name="ButtonCreateButton"><a class="button primary button-wrapper" href="https://blog.stuffandcode.com/subscribe?"><span>Abonnez-vous maintenant</span></a></p><div><hr></div>]]></content:encoded></item><item><title><![CDATA[Optimisez la vitesse et la mémoire de votre code Python avec __slots__]]></title><description><![CDATA[Qu'est-ce que __slots__ ? Quand est-ce que nous pouvons l'utiliser ? Cela fait-il vraiment la diff&#233;rence ? Plongeons-nous dans ce sujet.]]></description><link>https://blog.stuffandcode.com/p/optimisez-la-vitesse-et-la-memoire</link><guid isPermaLink="false">https://blog.stuffandcode.com/p/optimisez-la-vitesse-et-la-memoire</guid><dc:creator><![CDATA[Téva KRIEF]]></dc:creator><pubDate>Tue, 30 Jan 2024 09:00:28 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!RH5Z!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58a4bc80-7080-4511-bd4d-0535072fc2e1_1024x1024.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!RH5Z!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58a4bc80-7080-4511-bd4d-0535072fc2e1_1024x1024.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!RH5Z!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58a4bc80-7080-4511-bd4d-0535072fc2e1_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!RH5Z!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58a4bc80-7080-4511-bd4d-0535072fc2e1_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!RH5Z!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58a4bc80-7080-4511-bd4d-0535072fc2e1_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!RH5Z!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58a4bc80-7080-4511-bd4d-0535072fc2e1_1024x1024.webp 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!RH5Z!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58a4bc80-7080-4511-bd4d-0535072fc2e1_1024x1024.webp" width="1024" height="1024" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/58a4bc80-7080-4511-bd4d-0535072fc2e1_1024x1024.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1024,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;A vibrant digital illustration featuring the Python logo moving at high speed. The logo is depicted as if it's racing forward, with dynamic speed lines and motion blur effects surrounding it, symbolizing rapid performance and efficiency in Python programming. The background is a sleek, digital landscape, suggesting a high-tech environment, and further emphasizing the theme of speed and advanced coding capabilities in Python.&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="A vibrant digital illustration featuring the Python logo moving at high speed. The logo is depicted as if it's racing forward, with dynamic speed lines and motion blur effects surrounding it, symbolizing rapid performance and efficiency in Python programming. The background is a sleek, digital landscape, suggesting a high-tech environment, and further emphasizing the theme of speed and advanced coding capabilities in Python." title="A vibrant digital illustration featuring the Python logo moving at high speed. The logo is depicted as if it's racing forward, with dynamic speed lines and motion blur effects surrounding it, symbolizing rapid performance and efficiency in Python programming. The background is a sleek, digital landscape, suggesting a high-tech environment, and further emphasizing the theme of speed and advanced coding capabilities in Python." srcset="https://substackcdn.com/image/fetch/$s_!RH5Z!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58a4bc80-7080-4511-bd4d-0535072fc2e1_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!RH5Z!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58a4bc80-7080-4511-bd4d-0535072fc2e1_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!RH5Z!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58a4bc80-7080-4511-bd4d-0535072fc2e1_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!RH5Z!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58a4bc80-7080-4511-bd4d-0535072fc2e1_1024x1024.webp 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><h1>Qu'est-ce que __slots__ ?</h1><p></p><p><code>TL;DR: __slots__</code> en Python est utilis&#233; pour limiter les attributs qui peuvent &#234;tre d&#233;finis dans une classe.</p><p></p><p><code>__slots__ </code>est un <strong>attribut de classe</strong> qui contient g&#233;n&#233;ralement des strings.</p><p>Lorsque __<code>slots__</code> est d&#233;fini dans une classe, les instances de cette classe ne peuvent avoir que les attributs sp&#233;cifi&#233;s dans __<code>slots__</code>.</p><p>L'utilisation de __<code>slots__</code> peut &#234;tre utile pour &#233;conomiser de l'espace m&#233;moire en limitant le nombre d'attributs d'une instance. </p><p>Par exemple, si une classe n'a besoin que de quelques attributs et que nous savons que nous n&#8217;aurons pas besoin d&#8217;ajouter des attributs de mani&#232;re dynamique, il peut &#234;tre avantageux de les sp&#233;cifier dans __<code>slots__</code> .</p><p></p><h2>Une classe normale</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!G3FZ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08904d78-7147-4013-aa43-8250dd50dbb1_1864x928.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!G3FZ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08904d78-7147-4013-aa43-8250dd50dbb1_1864x928.png 424w, https://substackcdn.com/image/fetch/$s_!G3FZ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08904d78-7147-4013-aa43-8250dd50dbb1_1864x928.png 848w, https://substackcdn.com/image/fetch/$s_!G3FZ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08904d78-7147-4013-aa43-8250dd50dbb1_1864x928.png 1272w, https://substackcdn.com/image/fetch/$s_!G3FZ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08904d78-7147-4013-aa43-8250dd50dbb1_1864x928.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!G3FZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08904d78-7147-4013-aa43-8250dd50dbb1_1864x928.png" width="1456" height="725" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/08904d78-7147-4013-aa43-8250dd50dbb1_1864x928.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:725,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:104926,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!G3FZ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08904d78-7147-4013-aa43-8250dd50dbb1_1864x928.png 424w, https://substackcdn.com/image/fetch/$s_!G3FZ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08904d78-7147-4013-aa43-8250dd50dbb1_1864x928.png 848w, https://substackcdn.com/image/fetch/$s_!G3FZ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08904d78-7147-4013-aa43-8250dd50dbb1_1864x928.png 1272w, https://substackcdn.com/image/fetch/$s_!G3FZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08904d78-7147-4013-aa43-8250dd50dbb1_1864x928.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><br>Nous pouvons acc&#233;der &#224; l&#8217;attribut <code>__dict__</code> et &#233;galement assigner un nouvel attribut dynamiquement sans soucis. </p><p></p><h2>Une classe avec __slots__</h2><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!JqEA!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc5f4aff-d691-47e9-952b-95652a1d5523_1864x1256.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!JqEA!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc5f4aff-d691-47e9-952b-95652a1d5523_1864x1256.png 424w, https://substackcdn.com/image/fetch/$s_!JqEA!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc5f4aff-d691-47e9-952b-95652a1d5523_1864x1256.png 848w, https://substackcdn.com/image/fetch/$s_!JqEA!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc5f4aff-d691-47e9-952b-95652a1d5523_1864x1256.png 1272w, https://substackcdn.com/image/fetch/$s_!JqEA!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc5f4aff-d691-47e9-952b-95652a1d5523_1864x1256.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!JqEA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc5f4aff-d691-47e9-952b-95652a1d5523_1864x1256.png" width="1456" height="981" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/fc5f4aff-d691-47e9-952b-95652a1d5523_1864x1256.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:981,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:164773,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!JqEA!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc5f4aff-d691-47e9-952b-95652a1d5523_1864x1256.png 424w, https://substackcdn.com/image/fetch/$s_!JqEA!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc5f4aff-d691-47e9-952b-95652a1d5523_1864x1256.png 848w, https://substackcdn.com/image/fetch/$s_!JqEA!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc5f4aff-d691-47e9-952b-95652a1d5523_1864x1256.png 1272w, https://substackcdn.com/image/fetch/$s_!JqEA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc5f4aff-d691-47e9-952b-95652a1d5523_1864x1256.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><br>Ici, nous avons d&#233;fini <code>__slots__</code> avec un tuple qui contient une string &#8220;<strong>x</strong>&#8221;, ce qui signifie que nos instances ne pourront avoir qu&#8217;un seul attribut qui s&#8217;appelle <strong>x</strong>. Avoir d&#8217;autres attributs est impossible.<br><br>Par exemple, en regardant la ligne 9, si l&#8217;on essaie d&#8217;assigner un autre attribut comme ce que nous avons fait dans l&#8217;autre classe nous allons obtenir une <strong>AttributeError</strong>.</p><p>De la m&#234;me mani&#232;re, comme nous l&#8217;avons expliqu&#233;, l&#8217;attribut <code>__dict__</code> n&#8217;existe pas dans ce contexte et g&#233;n&#232;re donc un <strong>AttributeError</strong>.</p><p></p><p>Si vous utilisez des dataclasses, vous pouvez &#233;galement utiliser <code>__slots__</code> facilement, et ceci aura le m&#234;me effet que pr&#233;c&#233;demment.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!dVFR!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F533d2de4-9028-4cc6-87e4-2a8469b4196c_1344x260.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!dVFR!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F533d2de4-9028-4cc6-87e4-2a8469b4196c_1344x260.png 424w, https://substackcdn.com/image/fetch/$s_!dVFR!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F533d2de4-9028-4cc6-87e4-2a8469b4196c_1344x260.png 848w, https://substackcdn.com/image/fetch/$s_!dVFR!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F533d2de4-9028-4cc6-87e4-2a8469b4196c_1344x260.png 1272w, https://substackcdn.com/image/fetch/$s_!dVFR!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F533d2de4-9028-4cc6-87e4-2a8469b4196c_1344x260.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!dVFR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F533d2de4-9028-4cc6-87e4-2a8469b4196c_1344x260.png" width="1344" height="260" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/533d2de4-9028-4cc6-87e4-2a8469b4196c_1344x260.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:260,&quot;width&quot;:1344,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:29974,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!dVFR!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F533d2de4-9028-4cc6-87e4-2a8469b4196c_1344x260.png 424w, https://substackcdn.com/image/fetch/$s_!dVFR!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F533d2de4-9028-4cc6-87e4-2a8469b4196c_1344x260.png 848w, https://substackcdn.com/image/fetch/$s_!dVFR!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F533d2de4-9028-4cc6-87e4-2a8469b4196c_1344x260.png 1272w, https://substackcdn.com/image/fetch/$s_!dVFR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F533d2de4-9028-4cc6-87e4-2a8469b4196c_1344x260.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p></p><div><hr></div><p>Si vous appr&#233;ciez la newsletter StuffAndCode, vous pouvez vous inscrire afin de ne manquer aucun article ! </p><p>&#128013; Et recevez en PLUS, un <strong>article exclusif</strong> sur comment profiler n&#8217;importe quel type de code Python.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.stuffandcode.com/subscribe?&quot;,&quot;text&quot;:&quot;Abonnez-vous maintenant&quot;,&quot;action&quot;:null,&quot;class&quot;:&quot;button-wrapper&quot;}" data-component-name="ButtonCreateButton"><a class="button primary button-wrapper" href="https://blog.stuffandcode.com/subscribe?"><span>Abonnez-vous maintenant</span></a></p><div><hr></div><h1>Mesurons les performances</h1><p>Nous allons comparer deux scripts qui font la m&#234;me chose. </p><p>La seule diff&#233;rence est que l&#8217;attribut &#8220;<strong>x</strong>&#8221; sera d&#233;fini dans le <code>__slots__</code> du deuxi&#232;me script. </p><p></p><p>Voici notre premier script : </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Hg1e!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48f2ba6a-dc10-4f18-9756-116e66c7972e_1864x1256.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Hg1e!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48f2ba6a-dc10-4f18-9756-116e66c7972e_1864x1256.png 424w, https://substackcdn.com/image/fetch/$s_!Hg1e!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48f2ba6a-dc10-4f18-9756-116e66c7972e_1864x1256.png 848w, https://substackcdn.com/image/fetch/$s_!Hg1e!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48f2ba6a-dc10-4f18-9756-116e66c7972e_1864x1256.png 1272w, https://substackcdn.com/image/fetch/$s_!Hg1e!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48f2ba6a-dc10-4f18-9756-116e66c7972e_1864x1256.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Hg1e!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48f2ba6a-dc10-4f18-9756-116e66c7972e_1864x1256.png" width="1456" height="981" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/48f2ba6a-dc10-4f18-9756-116e66c7972e_1864x1256.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:981,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:158020,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Hg1e!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48f2ba6a-dc10-4f18-9756-116e66c7972e_1864x1256.png 424w, https://substackcdn.com/image/fetch/$s_!Hg1e!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48f2ba6a-dc10-4f18-9756-116e66c7972e_1864x1256.png 848w, https://substackcdn.com/image/fetch/$s_!Hg1e!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48f2ba6a-dc10-4f18-9756-116e66c7972e_1864x1256.png 1272w, https://substackcdn.com/image/fetch/$s_!Hg1e!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48f2ba6a-dc10-4f18-9756-116e66c7972e_1864x1256.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>Et voici notre second script : </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!x5jM!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb75015bb-a41d-49ec-8dfc-33eb5312181c_1864x1256.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!x5jM!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb75015bb-a41d-49ec-8dfc-33eb5312181c_1864x1256.png 424w, https://substackcdn.com/image/fetch/$s_!x5jM!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb75015bb-a41d-49ec-8dfc-33eb5312181c_1864x1256.png 848w, https://substackcdn.com/image/fetch/$s_!x5jM!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb75015bb-a41d-49ec-8dfc-33eb5312181c_1864x1256.png 1272w, https://substackcdn.com/image/fetch/$s_!x5jM!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb75015bb-a41d-49ec-8dfc-33eb5312181c_1864x1256.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!x5jM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb75015bb-a41d-49ec-8dfc-33eb5312181c_1864x1256.png" width="1456" height="981" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b75015bb-a41d-49ec-8dfc-33eb5312181c_1864x1256.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:981,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:156131,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!x5jM!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb75015bb-a41d-49ec-8dfc-33eb5312181c_1864x1256.png 424w, https://substackcdn.com/image/fetch/$s_!x5jM!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb75015bb-a41d-49ec-8dfc-33eb5312181c_1864x1256.png 848w, https://substackcdn.com/image/fetch/$s_!x5jM!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb75015bb-a41d-49ec-8dfc-33eb5312181c_1864x1256.png 1272w, https://substackcdn.com/image/fetch/$s_!x5jM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb75015bb-a41d-49ec-8dfc-33eb5312181c_1864x1256.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>Si l&#8217;on d&#233;cide de profiler avec <a href="https://blog.stuffandcode.com/p/les-differents-types-de-profilers">cProfile </a>nos scripts, nous obtenons ces r&#233;sultats : </p><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ui7m!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd67fa7ee-4afd-468b-9972-5d85507b1dd6_2318x1578.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ui7m!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd67fa7ee-4afd-468b-9972-5d85507b1dd6_2318x1578.png 424w, https://substackcdn.com/image/fetch/$s_!ui7m!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd67fa7ee-4afd-468b-9972-5d85507b1dd6_2318x1578.png 848w, https://substackcdn.com/image/fetch/$s_!ui7m!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd67fa7ee-4afd-468b-9972-5d85507b1dd6_2318x1578.png 1272w, https://substackcdn.com/image/fetch/$s_!ui7m!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd67fa7ee-4afd-468b-9972-5d85507b1dd6_2318x1578.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ui7m!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd67fa7ee-4afd-468b-9972-5d85507b1dd6_2318x1578.png" width="1456" height="991" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d67fa7ee-4afd-468b-9972-5d85507b1dd6_2318x1578.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:991,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:240583,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ui7m!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd67fa7ee-4afd-468b-9972-5d85507b1dd6_2318x1578.png 424w, https://substackcdn.com/image/fetch/$s_!ui7m!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd67fa7ee-4afd-468b-9972-5d85507b1dd6_2318x1578.png 848w, https://substackcdn.com/image/fetch/$s_!ui7m!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd67fa7ee-4afd-468b-9972-5d85507b1dd6_2318x1578.png 1272w, https://substackcdn.com/image/fetch/$s_!ui7m!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd67fa7ee-4afd-468b-9972-5d85507b1dd6_2318x1578.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>Nous pouvons constater un gain de performance de 1.24x plus rapide ou 23.53% plus rapide en sp&#233;cifiant le <code>__slots__</code>.</p><p></p><h1>Mesurons la m&#233;moire</h1><p>Nous l&#8217;avons dit, un des int&#233;rets de <code>__slots__</code> est surtout lorsque nous avons beaucoup d&#8217;instances de cet objet l&#224;. </p><p>Nous avons vu que c&#8217;&#233;tait d&#233;j&#224; bien plus rapide, mais qu&#8217;en est t-il de la <strong>m&#233;moire</strong> que nous pouvons &#233;conomiser ? </p><p></p><p>Pour ceci nous allons mesurer avec un profiler de m&#233;moire appel&#233; &#8220;<a href="https://github.com/pythonspeed/filprofiler">filprofiler</a>&#8221;.</p><p></p><p>Voici les r&#233;sultats pour la version sans <code>__slots__</code> </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!BHfY!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa705a8af-ede1-474d-b97d-a8cfb5d1c4e1_1124x347.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!BHfY!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa705a8af-ede1-474d-b97d-a8cfb5d1c4e1_1124x347.png 424w, https://substackcdn.com/image/fetch/$s_!BHfY!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa705a8af-ede1-474d-b97d-a8cfb5d1c4e1_1124x347.png 848w, https://substackcdn.com/image/fetch/$s_!BHfY!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa705a8af-ede1-474d-b97d-a8cfb5d1c4e1_1124x347.png 1272w, https://substackcdn.com/image/fetch/$s_!BHfY!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa705a8af-ede1-474d-b97d-a8cfb5d1c4e1_1124x347.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!BHfY!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa705a8af-ede1-474d-b97d-a8cfb5d1c4e1_1124x347.png" width="1124" height="347" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a705a8af-ede1-474d-b97d-a8cfb5d1c4e1_1124x347.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:347,&quot;width&quot;:1124,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:59300,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!BHfY!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa705a8af-ede1-474d-b97d-a8cfb5d1c4e1_1124x347.png 424w, https://substackcdn.com/image/fetch/$s_!BHfY!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa705a8af-ede1-474d-b97d-a8cfb5d1c4e1_1124x347.png 848w, https://substackcdn.com/image/fetch/$s_!BHfY!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa705a8af-ede1-474d-b97d-a8cfb5d1c4e1_1124x347.png 1272w, https://substackcdn.com/image/fetch/$s_!BHfY!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa705a8af-ede1-474d-b97d-a8cfb5d1c4e1_1124x347.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Et voici les r&#233;sultats avec <code>__slots__</code> </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!D6NO!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66056dca-849d-4bce-9f49-b4d42f8cf4a2_1121x346.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!D6NO!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66056dca-849d-4bce-9f49-b4d42f8cf4a2_1121x346.png 424w, https://substackcdn.com/image/fetch/$s_!D6NO!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66056dca-849d-4bce-9f49-b4d42f8cf4a2_1121x346.png 848w, https://substackcdn.com/image/fetch/$s_!D6NO!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66056dca-849d-4bce-9f49-b4d42f8cf4a2_1121x346.png 1272w, https://substackcdn.com/image/fetch/$s_!D6NO!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66056dca-849d-4bce-9f49-b4d42f8cf4a2_1121x346.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!D6NO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66056dca-849d-4bce-9f49-b4d42f8cf4a2_1121x346.png" width="1121" height="346" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/66056dca-849d-4bce-9f49-b4d42f8cf4a2_1121x346.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:346,&quot;width&quot;:1121,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:62119,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!D6NO!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66056dca-849d-4bce-9f49-b4d42f8cf4a2_1121x346.png 424w, https://substackcdn.com/image/fetch/$s_!D6NO!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66056dca-849d-4bce-9f49-b4d42f8cf4a2_1121x346.png 848w, https://substackcdn.com/image/fetch/$s_!D6NO!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66056dca-849d-4bce-9f49-b4d42f8cf4a2_1121x346.png 1272w, https://substackcdn.com/image/fetch/$s_!D6NO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66056dca-849d-4bce-9f49-b4d42f8cf4a2_1121x346.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><br>Le r&#233;sultat est flagrant, nous avons donc une consommation de m&#233;moire 1.82 fois moindre, soit une r&#233;duction de 54.8%, ce qui est assez &#233;norme.</p><p></p><p>Il faut cependant se rappeler que dans ce cas pr&#233;cis nous avons 1 million d&#8217;instances. Ce qui peut potentiellement vous arriver en fonction de votre cas d&#8217;usage.</p><p>Si jamais vous avez peu d&#8217;instances, vous ne verrez pas un gain de performance aussi &#233;lev&#233; que ce que nous avons obtenu.</p><p></p><p>Vous pouvez trouver plus de documentation <a href="https://wiki.python.org/moin/UsingSlots">ici</a>.</p><h1>Quizz Time</h1><p>Allez, c&#8217;est parti pour quelques petites questions :</p><ul><li><p>Quels sont les int&#233;r&#234;ts d&#8217;utiliser <code>__slots__</code> ?</p></li><li><p>Que met-on dans l&#8217;attribut de classe <code>__slots__</code> ?</p></li><li><p>Quand pouvons-nous profiter au maximum de l&#8217;utilisation de <code>__slots__</code> ?</p></li><li><p>Qu&#8217;avons nous utilis&#233; pour profiler la m&#233;moire ?</p></li></ul><p></p><div><hr></div><p>Si vous appr&#233;ciez la newsletter StuffAndCode, vous pouvez vous inscrire afin de ne manquer aucun article ! </p><p>&#128013; Et recevez en PLUS, un <strong>article exclusif</strong> sur comment profiler n&#8217;importe quel type de code Python.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.stuffandcode.com/subscribe?&quot;,&quot;text&quot;:&quot;Abonnez-vous maintenant&quot;,&quot;action&quot;:null,&quot;class&quot;:&quot;button-wrapper&quot;}" data-component-name="ButtonCreateButton"><a class="button primary button-wrapper" href="https://blog.stuffandcode.com/subscribe?"><span>Abonnez-vous maintenant</span></a></p><div><hr></div>]]></content:encoded></item><item><title><![CDATA[Comment j'ai accéléré de 22x la vitesse de mon script Python]]></title><description><![CDATA[Un script qui prend 1 minute et qui passe a 2 secondes, comment avons-nous fait ? Plongeons dans cette &#233;pop&#233;e !]]></description><link>https://blog.stuffandcode.com/p/comment-jai-accelere-de-22x-la-vitesse</link><guid isPermaLink="false">https://blog.stuffandcode.com/p/comment-jai-accelere-de-22x-la-vitesse</guid><dc:creator><![CDATA[Téva KRIEF]]></dc:creator><pubDate>Tue, 23 Jan 2024 09:00:11 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!lLEM!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fec7bb6-b1ff-4331-b671-2523661dc4ba_1024x1024.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p></p><p><em>Cet article est le premier d&#8217;une s&#233;rie. Nous avons augment&#233; de 22x les performances de notre script Python, ce qui est honorable, mais peut-&#234;tre pourrons nous aller plus loin ?</em> </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!lLEM!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fec7bb6-b1ff-4331-b671-2523661dc4ba_1024x1024.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!lLEM!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fec7bb6-b1ff-4331-b671-2523661dc4ba_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!lLEM!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fec7bb6-b1ff-4331-b671-2523661dc4ba_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!lLEM!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fec7bb6-b1ff-4331-b671-2523661dc4ba_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!lLEM!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fec7bb6-b1ff-4331-b671-2523661dc4ba_1024x1024.webp 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!lLEM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fec7bb6-b1ff-4331-b671-2523661dc4ba_1024x1024.webp" width="1024" height="1024" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6fec7bb6-b1ff-4331-b671-2523661dc4ba_1024x1024.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1024,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:221416,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/webp&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!lLEM!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fec7bb6-b1ff-4331-b671-2523661dc4ba_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!lLEM!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fec7bb6-b1ff-4331-b671-2523661dc4ba_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!lLEM!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fec7bb6-b1ff-4331-b671-2523661dc4ba_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!lLEM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fec7bb6-b1ff-4331-b671-2523661dc4ba_1024x1024.webp 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h1>Le probl&#232;me</h1><p>J&#8217;ai voulu &#233;crire un script qui me permet de d&#233;tecter quels sont <strong>les pixels les plus fr&#233;quents sur un ensemble d&#8217;images</strong>.  Est-ce le blanc, le noir, d&#8217;autres ? </p><p>Lorsque nous travaillons sur un petit volume d&#8217;image, ce n&#8217;est pas un souci, Mais lorsque le volume d'images augmente, par exemple pour des dizaines d'images, le temps de traitement devient un enjeu significatif.</p><p>Nous allons voir dans cet article comment &#224; partir d&#8217;un script le plus simple possible mais peu performant, nous pouvons arriver &#224; un script aux performances bien plus &#233;lev&#233;es.</p><p></p><h1>1) La version na&#239;ve </h1><p></p><p>Partons du principe que nous voulons <strong>t&#233;l&#233;charger 200 images,</strong> et les analyser pour compter les pixels les plus fr&#233;quemment rencontr&#233;s. Nous pourrons donc identifier les couleurs dominantes.</p><p></p><p><em>Note : Pour garantir une constance dans les r&#233;sultats lors des benchmarks, j'ai choisi <strong>d'h&#233;berger les images localement</strong>.</em> </p><p><em>De plus, j'ai mis en place <strong>un d&#233;lai artificiel de 100ms</strong> pour simuler une connexion &#224; un site distant. Cette simulation nous aide &#224; mieux repr&#233;senter les conditions r&#233;elles d'une application en ligne.</em></p><p></p><p><em>Note : La performance de chaque script a &#233;t&#233; &#233;valu&#233;e dans un environnement contr&#244;l&#233;, sur la m&#234;me machine et dans des conditions aussi similaires que possible. </em></p><p><em>Pour cela, j'ai d&#233;velopp&#233; un script, qui e<strong>x&#233;cute chaque script &#224; tester 5 fois</strong> et mesure le temps d'ex&#233;cution gr&#226;ce &#224; la fonction <strong>time.perf_counter</strong>. </em></p><p><em>Nous calculons ainsi la moyenne (mean) et l'&#233;cart-type (stdev) des temps d'ex&#233;cution pour obtenir une &#233;valuation pr&#233;cise des performances.</em></p><p><em>Ces donn&#233;es nous permettent de comparer les scripts de mani&#232;re plus nuanc&#233;e et d&#233;taill&#233;e.</em></p><p><em>Aussi, nous mettons en avant le temps d'acc&#233;l&#233;ration par rapport &#224; la version initiale du script. C'est pourquoi la premi&#232;re version, &#233;tant notre point de r&#233;f&#233;rence, pr&#233;sente un facteur d'acc&#233;l&#233;ration (<strong>speedup</strong>) de 1x.</em></p><p><em>Un speedup &lt; 1 signifie donc une d&#233;gradation des performances par rapport au script initial.</em></p><p></p><p>Voici notre script initial : </p><p><em><strong>Je vous invite &#224; regarder les extraits de code qui vous seront montr&#233;s tout au long de cet article et d&#8217;essayer d&#8217;observer quelles sont les diff&#233;rences entre chaque version. Cela vous donnera une meilleure compr&#233;hension globale et vous habituera aux syntaxes utilis&#233;es.</strong></em></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!mfdM!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F439040f1-ea53-447c-931a-ff8108032c1c_2436x3612.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!mfdM!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F439040f1-ea53-447c-931a-ff8108032c1c_2436x3612.png 424w, https://substackcdn.com/image/fetch/$s_!mfdM!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F439040f1-ea53-447c-931a-ff8108032c1c_2436x3612.png 848w, https://substackcdn.com/image/fetch/$s_!mfdM!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F439040f1-ea53-447c-931a-ff8108032c1c_2436x3612.png 1272w, https://substackcdn.com/image/fetch/$s_!mfdM!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F439040f1-ea53-447c-931a-ff8108032c1c_2436x3612.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!mfdM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F439040f1-ea53-447c-931a-ff8108032c1c_2436x3612.png" width="728" height="1079.5" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/439040f1-ea53-447c-931a-ff8108032c1c_2436x3612.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:false,&quot;imageSize&quot;:&quot;normal&quot;,&quot;height&quot;:2159,&quot;width&quot;:1456,&quot;resizeWidth&quot;:728,&quot;bytes&quot;:680716,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!mfdM!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F439040f1-ea53-447c-931a-ff8108032c1c_2436x3612.png 424w, https://substackcdn.com/image/fetch/$s_!mfdM!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F439040f1-ea53-447c-931a-ff8108032c1c_2436x3612.png 848w, https://substackcdn.com/image/fetch/$s_!mfdM!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F439040f1-ea53-447c-931a-ff8108032c1c_2436x3612.png 1272w, https://substackcdn.com/image/fetch/$s_!mfdM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F439040f1-ea53-447c-931a-ff8108032c1c_2436x3612.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>Ce script est certainement la mani&#232;re la plus na&#239;ve d&#8217;&#233;crire une solution pour ce probl&#232;me. On it&#232;re sur chacune des URL, on r&#233;cup&#232;re l&#8217;image (sans la stocker), et une fois toutes les images acquises, on it&#232;re dessus pour comptabiliser les pixels et enrichir un dictionnaire. Ensuite, nous utilisons l&#8217;objet <strong>Counter</strong> du module <strong>collections</strong> afin d&#8217;obtenir les pixels les plus courants.</p><p></p><p>Lorsque nous mesurons le temps d&#8217;ex&#233;cution de ce script nous constatons : </p><p><code>v1: Mean = 59.17s, Stdev = 9.09s, Speedup = 1.00x </code></p><p></p><p>Ce temps semble assez long (<strong>pratiquement 1 minute</strong> pour traiter 200 images), tentons d&#8217;optimiser cela.</p><h1>2) La version asynchrone</h1><p>Nous avons vu que la premi&#232;re &#233;tape consiste &#224; t&#233;l&#233;charger des images en masse; c&#8217;est typiquement une <strong>probl&#233;matique IO,</strong> et les images sont ind&#233;pendantes les unes des autres. C&#8217;est un bon candidat afin d&#8217;ajouter de la concurrence.</p><p>Nous allons continuer &#224; utiliser le module <strong>httpx,</strong> mais nous allons l&#8217;utiliser en mode asynchrone avec le module <strong>asyncio</strong> afin de pouvoir envoyer plusieurs requ&#234;tes en m&#234;me temps.  </p><p>On peut facilement ex&#233;cuter les 200 coroutines en simultan&#233;es gr&#226;ce &#224; <strong>asyncio.gather</strong> et r&#233;cup&#233;rer tous les r&#233;sultats d&#8217;un coup. </p><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!iyc5!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22f88cc5-0d32-4c82-8d5c-f787d4569895_2436x3744.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!iyc5!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22f88cc5-0d32-4c82-8d5c-f787d4569895_2436x3744.png 424w, https://substackcdn.com/image/fetch/$s_!iyc5!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22f88cc5-0d32-4c82-8d5c-f787d4569895_2436x3744.png 848w, https://substackcdn.com/image/fetch/$s_!iyc5!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22f88cc5-0d32-4c82-8d5c-f787d4569895_2436x3744.png 1272w, https://substackcdn.com/image/fetch/$s_!iyc5!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22f88cc5-0d32-4c82-8d5c-f787d4569895_2436x3744.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!iyc5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22f88cc5-0d32-4c82-8d5c-f787d4569895_2436x3744.png" width="1456" height="2238" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/22f88cc5-0d32-4c82-8d5c-f787d4569895_2436x3744.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:2238,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:759070,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!iyc5!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22f88cc5-0d32-4c82-8d5c-f787d4569895_2436x3744.png 424w, https://substackcdn.com/image/fetch/$s_!iyc5!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22f88cc5-0d32-4c82-8d5c-f787d4569895_2436x3744.png 848w, https://substackcdn.com/image/fetch/$s_!iyc5!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22f88cc5-0d32-4c82-8d5c-f787d4569895_2436x3744.png 1272w, https://substackcdn.com/image/fetch/$s_!iyc5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22f88cc5-0d32-4c82-8d5c-f787d4569895_2436x3744.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>Voici les r&#233;sultats pour ce script : </p><p><code>tutov2: Mean = 38.85s, Stdev = 0.27s, Speedup = 1.52x</code><br><br>Sans trop de surprises, <strong>nous avons gagn&#233; ~20 secondes</strong>, car il y a 200 images qui r&#233;pondent avec un d&#233;lai d&#8217;au moins 100ms. Voici un bon d&#233;but. </p><p>Voyons voir si nous pouvons mieux faire. </p><p></p><h1>3) Utilisation de ProcessPoolExecutor</h1><p>Nous avons r&#233;ussi &#224; impl&#233;menter de la concurrence afin de pouvoir r&#233;duire le temps de t&#233;l&#233;chargement des images. Pouvons_nous faire mieux en rajoutant du <strong>parall&#233;lisme</strong> dans notre programme ? </p><p>Lorsque nous parcourons nos pixels et les comptons, c&#8217;est une probl&#233;matique de calcul. Donc <strong>CPU</strong> et non plus IO. Cette fois <strong>asyncio</strong> ne nous sauvera pas.<br><br>De la m&#234;me mani&#232;re le module <strong>threading</strong> est inadapt&#233; aux probl&#233;matique CPU &#224; cause du <strong>GIL (Global Interpreter Lock)</strong>, qui, pour rappel, emp&#234;che plusieurs instructions Python de s&#8217;ex&#233;cuter en m&#234;me temps au sein d&#8217;un m&#234;me Process.</p><p>Ainsi nous allons utiliser le module <strong>concurrent.futures,</strong> et l&#8217;excellent<strong> ProcessPoolExecutor</strong> qui nous permet de mettre en place du <strong>multiprocessing</strong> facilement et d&#8217;ajouter du parall&#233;lisme &#224; notre programme.  </p><p></p><p></p><div><hr></div><p>Si vous appr&#233;ciez la newsletter StuffAndCode, vous pouvez vous inscrire afin de ne manquer aucun article ! </p><p>&#128013; Et recevez en PLUS, un <strong>article exclusif</strong> sur comment profiler n&#8217;importe quel type de code Python.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.stuffandcode.com/subscribe?&quot;,&quot;text&quot;:&quot;Abonnez-vous maintenant&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://blog.stuffandcode.com/subscribe?"><span>Abonnez-vous maintenant</span></a></p><div><hr></div><p></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.stuffandcode.com/subscribe?&quot;,&quot;text&quot;:&quot;S'abonner&quot;,&quot;language&quot;:&quot;fr&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Merci de lire StuffAndCode Newsletter ! Abonnez-vous gratuitement pour recevoir de nouveaux posts et soutenir mon travail.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Tapez votre e-mail&#8230;" tabindex="-1"><input type="submit" class="button primary" value="S'abonner"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p><em>Note : Lorsqu&#8217;on d&#233;marre un process Python, il y a un <strong>main Thread</strong> qui s&#8217;ex&#233;cute et le <strong>GIL</strong> est pr&#233;sent dans chacun des processes. Si nous d&#233;marrons plusieurs processes avec un seul Thread, chacun aura son propre GIL. Ainsi, ils ne se g&#234;neront pas ,et nous obtiendrons du vrai parall&#233;lisme. <br>Cependant, d&#233;marrer des processes est plus couteux que de d&#233;marrer des Threads. De m&#234;me concernant le transfert des donn&#233;es entre processes.</em></p><p></p><p>Voici une impl&#233;mentation de &#8220;comment parall&#233;liser le comptage des pixels sur plusieurs processeurs&#8221;. </p><p>Nous avons &#233;galement remplac&#233; le syst&#232;me de dictionnaire pour compter directement avec le Counter.</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!v7JI!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F203af94b-1912-4cb6-8fe5-699e103ceb64_2404x3940.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!v7JI!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F203af94b-1912-4cb6-8fe5-699e103ceb64_2404x3940.png 424w, https://substackcdn.com/image/fetch/$s_!v7JI!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F203af94b-1912-4cb6-8fe5-699e103ceb64_2404x3940.png 848w, https://substackcdn.com/image/fetch/$s_!v7JI!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F203af94b-1912-4cb6-8fe5-699e103ceb64_2404x3940.png 1272w, https://substackcdn.com/image/fetch/$s_!v7JI!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F203af94b-1912-4cb6-8fe5-699e103ceb64_2404x3940.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!v7JI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F203af94b-1912-4cb6-8fe5-699e103ceb64_2404x3940.png" width="1456" height="2386" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/203af94b-1912-4cb6-8fe5-699e103ceb64_2404x3940.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:2386,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:831324,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!v7JI!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F203af94b-1912-4cb6-8fe5-699e103ceb64_2404x3940.png 424w, https://substackcdn.com/image/fetch/$s_!v7JI!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F203af94b-1912-4cb6-8fe5-699e103ceb64_2404x3940.png 848w, https://substackcdn.com/image/fetch/$s_!v7JI!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F203af94b-1912-4cb6-8fe5-699e103ceb64_2404x3940.png 1272w, https://substackcdn.com/image/fetch/$s_!v7JI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F203af94b-1912-4cb6-8fe5-699e103ceb64_2404x3940.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>Voici les r&#233;sultats pour cette version.</p><p><code>tutov3: Mean = 12.01s, Stdev = 0.68s, Speedup = 4.93x<br></code></p><p>On peut noter une am&#233;lioration significative du temps d&#8217;ex&#233;cution.</p><p>Nous obtenons <strong>12 secondes</strong> contre 59 secondes lors de la premi&#232;re version.<br>En cas de doute quant &#224; la pertinence de <strong>ProcessPoolExecutor</strong> ou de <strong>ThreadPoolExecutor</strong>, sachez que vous pouvez le changer facilement, puis relancer le programme afin de mesurer. Dans mon cas le programme <strong>avec le ThreadPoolExecutor</strong> prenait 18 secondes au lieu de 12 secondes. </p><p>Ce qui signifie que l&#8217;ajout du ProcessPoolExecutor est b&#233;n&#233;fique.</p><p></p><h1>4) Am&#233;lioration de notre Counter</h1><p>Okay, maintenant qu&#8217;on a parall&#233;lis&#233; nos t&#233;l&#233;chargements et nos traitements, quelles am&#233;liorations sont possibles ? C&#8217;est l&#224; qu&#8217;il devient int&#233;ressant d&#8217; utiliser des <strong>outils de profiling</strong>, comme d&#233;taill&#233; dans <a href="https://blog.stuffandcode.com/p/les-differents-types-de-profilers">cet article</a>.</p><p></p><p>Si on profile le code pr&#233;c&#233;dent (de la partie 3), on remarque que le Counter occupe une part significative du temps de traitement.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Xx6z!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe431f4ba-6a44-4be3-bb85-0a9f290f008d_1083x446.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Xx6z!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe431f4ba-6a44-4be3-bb85-0a9f290f008d_1083x446.png 424w, https://substackcdn.com/image/fetch/$s_!Xx6z!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe431f4ba-6a44-4be3-bb85-0a9f290f008d_1083x446.png 848w, https://substackcdn.com/image/fetch/$s_!Xx6z!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe431f4ba-6a44-4be3-bb85-0a9f290f008d_1083x446.png 1272w, https://substackcdn.com/image/fetch/$s_!Xx6z!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe431f4ba-6a44-4be3-bb85-0a9f290f008d_1083x446.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Xx6z!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe431f4ba-6a44-4be3-bb85-0a9f290f008d_1083x446.png" width="1083" height="446" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e431f4ba-6a44-4be3-bb85-0a9f290f008d_1083x446.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:446,&quot;width&quot;:1083,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:114972,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Xx6z!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe431f4ba-6a44-4be3-bb85-0a9f290f008d_1083x446.png 424w, https://substackcdn.com/image/fetch/$s_!Xx6z!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe431f4ba-6a44-4be3-bb85-0a9f290f008d_1083x446.png 848w, https://substackcdn.com/image/fetch/$s_!Xx6z!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe431f4ba-6a44-4be3-bb85-0a9f290f008d_1083x446.png 1272w, https://substackcdn.com/image/fetch/$s_!Xx6z!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe431f4ba-6a44-4be3-bb85-0a9f290f008d_1083x446.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p><em>Note : La dur&#233;e totale de 14.122s ne correspond pas exactement au temps pr&#233;c&#233;dent de 12.01s car, dans ce cas, nous avons profil&#233; une seule ex&#233;cution du code. De plus, le fait de profiler <strong>ajoute de l&#8217;overhead</strong> donc du temps suppl&#233;mentaire (chose qui n&#8217;est pas faite lorsque nous mesurons uniquement le temps d&#8217;ex&#233;cution).</em></p><p></p><p>Lorsque nous utilisons notre objet <strong>Counter</strong> pour compter et r&#233;cup&#233;rer les pixels les plus courants, nous stockons les pixels sous forme de <strong>tuple de trois int, RGB</strong>. Ce qui n&#8217;est pas optimal. Counter fonctionne bien mieux avec des valeurs num&#233;riques et plus simples. <br>C&#8217;est pour cela que nous allons ajouter une &#233;tape de conversion pour <strong>transformer un tuple sous forme (R, G, B) en un entier</strong> qui repr&#233;sente cette m&#234;me couleur. </p><p><br>Pour ce faire, nous allons cr&#233;er une fonction <strong>rgb_to_int</strong><code> </code>qui prend en param&#232;tre un tuple d&#8217;int retournant un entier &#233;quivalent &#224; ce tuple. <br></p><p>Pour ceux qui s'int&#233;ressent aux d&#233;tails techniques de la conversion de RGB &#224; un entier, voici une explication. Il est important de noter que, dans notre optimisation, <strong>nous rempla&#231;ons les tuples RGB dans notre Counter par de simples entiers.</strong></p><p></p><h2>4.1) Transformation d&#8217;un tuple RGB en entier</h2><p>Laissez-moi vous montrer comment une petite modification peut engendrer une grande diff&#233;rence.</p><p>On va prendre l&#8217;exemple de la couleur rose repr&#233;sent&#233;e par le code RGB (<strong>255, 0, 255</strong>).</p><pre><code>Conversion de RGB &#224; Int :

RGB : (255, 0, 255)
En binaire, cela donne : R = 11111111, G = 00000000, B = 11111111

Ensuite, on d&#233;cale ces valeurs :
    R d&#233;cal&#233; de 16 bits (&lt;&lt; 16) devient 111111110000000000000000
    G d&#233;cal&#233; de 8 bits (&lt;&lt; 8) reste 0000000000000000
    B reste inchang&#233; : 11111111

On combine ces valeurs pour obtenir : 111111110000000011111111 en binaire
Ce qui donne en entier : 16711935</code></pre><p>Pour simplifier, on prend chaque composante de couleur, et on la d&#233;cale pour former un seul nombre. Ce nombre unique repr&#233;sente notre couleur originale. Cela ressemble &#224; la mani&#232;re dont on g&#232;re les permissions sur Linux : Read (4), Write (2), Execute (1). Lorsqu'on veut toutes les permissions, on utilise le chiffre 7, qui est la somme de 4, 2 et 1.</p><p>Le principe du d&#233;calage en binaire, comme dans l'op&#233;ration &#171; 1 &lt;&lt; 2 &#187;, signifie que l'on prend le nombre 1, le convertit en binaire (0001), et d&#233;cale ses bits de deux places vers la gauche. Ainsi, 0001 devient 0100, ce qui &#233;quivaut &#224; 4 en d&#233;cimal.</p><p></p><p>Le code qui correspond &#224; cette op&#233;ration est celui-ci : </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!n6G1!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61567af1-b133-4556-969e-fcb774ea7a2d_2108x532.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!n6G1!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61567af1-b133-4556-969e-fcb774ea7a2d_2108x532.png 424w, https://substackcdn.com/image/fetch/$s_!n6G1!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61567af1-b133-4556-969e-fcb774ea7a2d_2108x532.png 848w, https://substackcdn.com/image/fetch/$s_!n6G1!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61567af1-b133-4556-969e-fcb774ea7a2d_2108x532.png 1272w, https://substackcdn.com/image/fetch/$s_!n6G1!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61567af1-b133-4556-969e-fcb774ea7a2d_2108x532.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!n6G1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61567af1-b133-4556-969e-fcb774ea7a2d_2108x532.png" width="1456" height="367" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/61567af1-b133-4556-969e-fcb774ea7a2d_2108x532.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:367,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:97962,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!n6G1!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61567af1-b133-4556-969e-fcb774ea7a2d_2108x532.png 424w, https://substackcdn.com/image/fetch/$s_!n6G1!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61567af1-b133-4556-969e-fcb774ea7a2d_2108x532.png 848w, https://substackcdn.com/image/fetch/$s_!n6G1!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61567af1-b133-4556-969e-fcb774ea7a2d_2108x532.png 1272w, https://substackcdn.com/image/fetch/$s_!n6G1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61567af1-b133-4556-969e-fcb774ea7a2d_2108x532.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><h2>4.2) Transformation de l&#8217;entier vers le code RGB</h2><p>Lorsque nous voulons afficher les r&#233;sultats, nous cherchons &#224; retrouver le code RGB initial. Donc, il nous faut un moyen <strong>d&#8217;inverser le calcul</strong> que nous avons fait. Voici comment cela fonctionne: </p><p></p><p>Le <strong>masquage binaire</strong> est une op&#233;ration qui permet d'isoler certains bits dans un nombre binaire. Dans le cas de la fonction <strong>int_to_rgb</strong>, le masque <strong>&amp; 0xFF</strong> est utilis&#233; pour extraire les 8 bits les plus bas d'un entier. Le masque <strong>0xFF est de l&#8217;hexadecimal </strong>et est &#233;quivalent &#224; <strong>11111111 en binaire</strong>. Ce qui signifie qu'il conserve les 8 bits avec lesquels il est compar&#233; et met tous les autres &#224; z&#233;ro.</p><p></p><pre><code>Entier : 16711935
Binaire : 111111110000000011111111

Extraction de Rouge (R) :
  D&#233;calage : &gt;&gt; 16 donne 11111111
  Masque : 11111111 &amp; 11111111 = 11111111
  R&#233;sultat : 255 (en d&#233;cimal)

Extraction de Vert (G) :
  D&#233;calage : &gt;&gt; 8 donne 0000000011111111
  Masque : 00000000 &amp; 11111111 = 00000000
  R&#233;sultat : 0 (en d&#233;cimal)

Extraction de Bleu (B) :
  Pas de d&#233;calage
  Masque : 11111111 &amp; 11111111 = 11111111
  R&#233;sultat : 255 (en d&#233;cimal)

RGB : (255, 0, 255)</code></pre><p></p><p>Lorsque nous faisons du d&#233;veloppement web, ou autre, nous ne sommes pas souvent confront&#233;s &#224; cette syntaxe. Aussi un peu de pratique peut &#234;tre b&#233;n&#233;fique. Le mieux est de d&#233;marrer un interpr&#233;teur Python et de faire quelques tests.</p><p></p><p>Le code repr&#233;sentant l&#8217;op&#233;ration de transformation d&#8217;entier vers RGB est celui-ci : </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!6ivC!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd65256c8-c920-4c19-9efd-cbc2f3e900d0_2108x600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!6ivC!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd65256c8-c920-4c19-9efd-cbc2f3e900d0_2108x600.png 424w, https://substackcdn.com/image/fetch/$s_!6ivC!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd65256c8-c920-4c19-9efd-cbc2f3e900d0_2108x600.png 848w, https://substackcdn.com/image/fetch/$s_!6ivC!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd65256c8-c920-4c19-9efd-cbc2f3e900d0_2108x600.png 1272w, https://substackcdn.com/image/fetch/$s_!6ivC!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd65256c8-c920-4c19-9efd-cbc2f3e900d0_2108x600.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!6ivC!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd65256c8-c920-4c19-9efd-cbc2f3e900d0_2108x600.png" width="1456" height="414" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d65256c8-c920-4c19-9efd-cbc2f3e900d0_2108x600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:414,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:123586,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!6ivC!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd65256c8-c920-4c19-9efd-cbc2f3e900d0_2108x600.png 424w, https://substackcdn.com/image/fetch/$s_!6ivC!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd65256c8-c920-4c19-9efd-cbc2f3e900d0_2108x600.png 848w, https://substackcdn.com/image/fetch/$s_!6ivC!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd65256c8-c920-4c19-9efd-cbc2f3e900d0_2108x600.png 1272w, https://substackcdn.com/image/fetch/$s_!6ivC!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd65256c8-c920-4c19-9efd-cbc2f3e900d0_2108x600.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>Fin de la parenth&#232;se. </p><p>Voyons le code complet.</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!_lXz!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6019980e-4fb2-4c0a-baa1-a08dcc63eea7_2860x5248.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!_lXz!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6019980e-4fb2-4c0a-baa1-a08dcc63eea7_2860x5248.png 424w, https://substackcdn.com/image/fetch/$s_!_lXz!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6019980e-4fb2-4c0a-baa1-a08dcc63eea7_2860x5248.png 848w, https://substackcdn.com/image/fetch/$s_!_lXz!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6019980e-4fb2-4c0a-baa1-a08dcc63eea7_2860x5248.png 1272w, https://substackcdn.com/image/fetch/$s_!_lXz!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6019980e-4fb2-4c0a-baa1-a08dcc63eea7_2860x5248.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!_lXz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6019980e-4fb2-4c0a-baa1-a08dcc63eea7_2860x5248.png" width="1456" height="2672" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6019980e-4fb2-4c0a-baa1-a08dcc63eea7_2860x5248.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:2672,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1093383,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!_lXz!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6019980e-4fb2-4c0a-baa1-a08dcc63eea7_2860x5248.png 424w, https://substackcdn.com/image/fetch/$s_!_lXz!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6019980e-4fb2-4c0a-baa1-a08dcc63eea7_2860x5248.png 848w, https://substackcdn.com/image/fetch/$s_!_lXz!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6019980e-4fb2-4c0a-baa1-a08dcc63eea7_2860x5248.png 1272w, https://substackcdn.com/image/fetch/$s_!_lXz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6019980e-4fb2-4c0a-baa1-a08dcc63eea7_2860x5248.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>Voici le r&#233;sultat pour ce script : </p><p><code>v4: Mean = 7.80s, Stdev = 0.61s, Speedup = 7.58x<br></code><br>Wow, le temps est bien r&#233;duit rien qu&#8217;avec cette modification. </p><p>Je n&#8217;aurai pas pens&#233; que <strong>le type de donn&#233;es utilis&#233;es par Counter</strong> pourrait avoir une influence aussi grande.</p><p></p><h1>5) Traitement par batch</h1><p>Nous l&#8217;avons &#233;voqu&#233; pr&#233;c&#233;demment, nous avons besoin de plusieurs processes afin de parall&#233;liser les calculs, car sinon cela prendrait trop de temps sur un seul processeur.<br>Cependant, le fait de compter les pixels n&#8217;est pas si long que &#231;a.  D&#233;marrer un nouveau process et faire transiter les data est co&#251;teux. <br><br>Ne serait_il pas possible de faire quelque chose &#224; ce niveau ? </p><p>Pourquoi ne pas traiter plusieurs images d&#8217;un coup, puis mettre &#224; jour un <strong>Counter</strong> pour un <strong>batch d&#8217;images ?</strong> </p><p>La m&#233;canique reste la m&#234;me, nous spawnons toujours autant de processes (les Process ne sont cr&#233;&#233;s qu&#8217;une fois et <strong>r&#233;utilis&#233;s</strong> gr&#226;ce au <strong>ProcessPoolExecutor</strong>), nous allons traiter plusieurs images d&#8217;un coup. Donc <strong>r&#233;duire le nombre de r&#233;utilisations </strong>de chaque process et aussi <strong>r&#233;duire le nombre de donn&#233;es</strong> qui doivent passer du process au main process pour avoir les r&#233;sultats finaux.</p><p>Car au lieu d&#8217;envoyer 200 (nombre d&#8217;images) fois des Counter, nous allons en envoyer plus que 20 (pour des batchs de 10 images). Ce qui &#233;vite la proc&#233;dure de pickling et unpickling qui consomme &#233;galement du temps.</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!0zC1!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff00ccda9-0812-46eb-9e53-d5d8365a0a5f_2988x5316.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!0zC1!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff00ccda9-0812-46eb-9e53-d5d8365a0a5f_2988x5316.png 424w, https://substackcdn.com/image/fetch/$s_!0zC1!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff00ccda9-0812-46eb-9e53-d5d8365a0a5f_2988x5316.png 848w, https://substackcdn.com/image/fetch/$s_!0zC1!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff00ccda9-0812-46eb-9e53-d5d8365a0a5f_2988x5316.png 1272w, https://substackcdn.com/image/fetch/$s_!0zC1!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff00ccda9-0812-46eb-9e53-d5d8365a0a5f_2988x5316.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!0zC1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff00ccda9-0812-46eb-9e53-d5d8365a0a5f_2988x5316.png" width="1456" height="2590" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f00ccda9-0812-46eb-9e53-d5d8365a0a5f_2988x5316.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:2590,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1207375,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!0zC1!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff00ccda9-0812-46eb-9e53-d5d8365a0a5f_2988x5316.png 424w, https://substackcdn.com/image/fetch/$s_!0zC1!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff00ccda9-0812-46eb-9e53-d5d8365a0a5f_2988x5316.png 848w, https://substackcdn.com/image/fetch/$s_!0zC1!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff00ccda9-0812-46eb-9e53-d5d8365a0a5f_2988x5316.png 1272w, https://substackcdn.com/image/fetch/$s_!0zC1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff00ccda9-0812-46eb-9e53-d5d8365a0a5f_2988x5316.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>Voici les r&#233;sultats pour cette version : </p><p><code>v5: Mean = 2.67s, Stdev = 0.03s, Speedup = 22.20x</code></p><p></p><p><strong>2.67s pour t&#233;l&#233;charger et traiter les 200 images, contre 59s &#224; la base, c&#8217;est pas trop mal.</strong></p><p>Nous avons donc accompli encore un joli pas en avant. </p><p>Le choix du nombre 10 pour les batches est <strong>arbitraire</strong>. Il est conseill&#233; d'exp&#233;rimenter avec diff&#233;rentes tailles de batch pour trouver le nombre le plus optimal, en augmentant ou diminuant cette valeur.</p><p></p><p>Voici le profiling. </p><p>Comme pr&#233;c&#233;demment, les r&#233;sultats sont diff&#233;rents en raison de l'overhead du profiling. Nous pouvons donc voir qu'il y a du temps pass&#233; dans le <strong>multiprocessing</strong> et &#233;galement que nous passons encore pas mal de temps dans le <code>Counter.update</code>. </p><p>Nous verrons si nous pouvons am&#233;liorer ces performances dans un prochain article !</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Exo8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7b2dbff-b799-4be9-99c4-b8f6f7a3ef28_1117x570.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Exo8!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7b2dbff-b799-4be9-99c4-b8f6f7a3ef28_1117x570.png 424w, https://substackcdn.com/image/fetch/$s_!Exo8!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7b2dbff-b799-4be9-99c4-b8f6f7a3ef28_1117x570.png 848w, https://substackcdn.com/image/fetch/$s_!Exo8!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7b2dbff-b799-4be9-99c4-b8f6f7a3ef28_1117x570.png 1272w, https://substackcdn.com/image/fetch/$s_!Exo8!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7b2dbff-b799-4be9-99c4-b8f6f7a3ef28_1117x570.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Exo8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7b2dbff-b799-4be9-99c4-b8f6f7a3ef28_1117x570.png" width="1117" height="570" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b7b2dbff-b799-4be9-99c4-b8f6f7a3ef28_1117x570.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:570,&quot;width&quot;:1117,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:134849,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Exo8!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7b2dbff-b799-4be9-99c4-b8f6f7a3ef28_1117x570.png 424w, https://substackcdn.com/image/fetch/$s_!Exo8!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7b2dbff-b799-4be9-99c4-b8f6f7a3ef28_1117x570.png 848w, https://substackcdn.com/image/fetch/$s_!Exo8!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7b2dbff-b799-4be9-99c4-b8f6f7a3ef28_1117x570.png 1272w, https://substackcdn.com/image/fetch/$s_!Exo8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7b2dbff-b799-4be9-99c4-b8f6f7a3ef28_1117x570.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h1>Les r&#233;sultats </h1><p>Si on compare les r&#233;sultats de toutes nos versions, nous obtenons ceci : </p><p><code>Results: <br>v1: Mean = 59.17s, Stdev = 9.09s, Speedup = 1.00x <br>v2: Mean = 38.85s, Stdev = 0.27s, Speedup = 1.52x <br>v3: Mean = 12.01s, Stdev = 0.68s, Speedup = 4.93x <br>v4: Mean = 7.80s, Stdev = 0.61s, Speedup = 7.58x <br>v5: Mean = 2.67s, Stdev = 0.03s, Speedup = 22.20x<br></code></p><h1>Les prochaines &#233;tapes ?</h1><p></p><p>Il existe d'autres optimisations que nous pourrions explorer. </p><p>Par exemple, envisager d'utiliser des biblioth&#232;ques comme <strong>Numpy</strong> ou <strong>Polars</strong>, qui ex&#233;cutent du code en <strong>C</strong> et <strong>Rust</strong> respectivement. Ces outils sont sp&#233;cialement optimis&#233;s pour le traitement efficace de donn&#233;es volumineuses.</p><p>Nous pourrions aussi choisir d'ex&#233;cuter notre code sur une autre impl&#233;mentation de Python que <strong>CPython</strong> (qui est l'impl&#233;mentation standard de Python). Des alternatives comme <strong>PyPy</strong> ou <strong>IronPython</strong> peuvent offrir des avantages en terme de performances pour certains types de t&#226;ches.</p><p>Une autre strat&#233;gie consiste &#224; &#233;crire certaines parties critiques de notre code en C, <strong>Cython</strong> ou <strong>Rust</strong>. </p><p>Et bien s&#251;r, il y a s&#251;rement d'autres m&#233;thodes d'optimisation &#224; d&#233;couvrir et &#224; exp&#233;rimenter. </p><p>Mais &#231;a, nous le garderons pour une prochaine fois !</p><h1></h1><p></p><div><hr></div><p>Si vous appr&#233;ciez la newsletter StuffAndCode, vous pouvez vous inscrire afin de ne manquer aucun article ! </p><p>&#128013; Et recevez en PLUS, un <strong>article exclusif</strong> sur comment profiler n&#8217;importe quel type de code Python.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.stuffandcode.com/subscribe?&quot;,&quot;text&quot;:&quot;Abonnez-vous maintenant&quot;,&quot;action&quot;:null,&quot;class&quot;:&quot;button-wrapper&quot;}" data-component-name="ButtonCreateButton"><a class="button primary button-wrapper" href="https://blog.stuffandcode.com/subscribe?"><span>Abonnez-vous maintenant</span></a></p><div><hr></div><p></p>]]></content:encoded></item><item><title><![CDATA[Les différents types de profilers et les mesures de temps]]></title><description><![CDATA[Les types de profilers Il existe deux types de profiling couramment utilis&#233;s en Python : le Deterministic Profiling et le Statistical Profiling.]]></description><link>https://blog.stuffandcode.com/p/les-differents-types-de-profilers</link><guid isPermaLink="false">https://blog.stuffandcode.com/p/les-differents-types-de-profilers</guid><dc:creator><![CDATA[Téva KRIEF]]></dc:creator><pubDate>Tue, 16 Jan 2024 09:00:35 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!YBH-!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42a134f2-a924-4aca-bb77-811cd8914ddf_1024x1024.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!YBH-!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42a134f2-a924-4aca-bb77-811cd8914ddf_1024x1024.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!YBH-!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42a134f2-a924-4aca-bb77-811cd8914ddf_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!YBH-!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42a134f2-a924-4aca-bb77-811cd8914ddf_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!YBH-!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42a134f2-a924-4aca-bb77-811cd8914ddf_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!YBH-!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42a134f2-a924-4aca-bb77-811cd8914ddf_1024x1024.webp 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!YBH-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42a134f2-a924-4aca-bb77-811cd8914ddf_1024x1024.webp" width="1024" height="1024" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/42a134f2-a924-4aca-bb77-811cd8914ddf_1024x1024.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1024,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;A vibrant and imaginative illustration of a Python profiler in action. The image shows a large, stylized magnifying glass hovering over lines of Python code, illuminating the code beneath. Inside the magnifying area, the code is transformed into a dynamic 3D visualization, with peaks and valleys indicating the performance of different sections of the code. The background is filled with digital motifs and Python logos, emphasizing the technological and coding theme. This representation captures the essence of a profiler analyzing and optimizing Python code.&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="A vibrant and imaginative illustration of a Python profiler in action. The image shows a large, stylized magnifying glass hovering over lines of Python code, illuminating the code beneath. Inside the magnifying area, the code is transformed into a dynamic 3D visualization, with peaks and valleys indicating the performance of different sections of the code. The background is filled with digital motifs and Python logos, emphasizing the technological and coding theme. This representation captures the essence of a profiler analyzing and optimizing Python code." title="A vibrant and imaginative illustration of a Python profiler in action. The image shows a large, stylized magnifying glass hovering over lines of Python code, illuminating the code beneath. Inside the magnifying area, the code is transformed into a dynamic 3D visualization, with peaks and valleys indicating the performance of different sections of the code. The background is filled with digital motifs and Python logos, emphasizing the technological and coding theme. This representation captures the essence of a profiler analyzing and optimizing Python code." srcset="https://substackcdn.com/image/fetch/$s_!YBH-!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42a134f2-a924-4aca-bb77-811cd8914ddf_1024x1024.webp 424w, https://substackcdn.com/image/fetch/$s_!YBH-!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42a134f2-a924-4aca-bb77-811cd8914ddf_1024x1024.webp 848w, https://substackcdn.com/image/fetch/$s_!YBH-!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42a134f2-a924-4aca-bb77-811cd8914ddf_1024x1024.webp 1272w, https://substackcdn.com/image/fetch/$s_!YBH-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42a134f2-a924-4aca-bb77-811cd8914ddf_1024x1024.webp 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><h1>1) Les types de profilers</h1><p>Il existe deux types de profiling couramment utilis&#233;s en Python : le <strong>Deterministic Profiling</strong> et le <strong>Statistical Profiling</strong>.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.stuffandcode.com/subscribe?&quot;,&quot;text&quot;:&quot;S'abonner&quot;,&quot;language&quot;:&quot;fr&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">StuffAndCode Newsletter est une publication soutenue par ses lecteurs. Pour recevoir de nouveaux posts et soutenir mon travail, envisagez de devenir un abonn&#233; gratuit ou payant.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Tapez votre e-mail&#8230;" tabindex="-1"><input type="submit" class="button primary" value="S'abonner"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p></p><p>Note : <em>Ici, on ne parle pas de profiling de m&#233;moire mais uniquement de profiling de performances.</em></p><p></p><h2><strong>1.1) Deterministic Profilers</strong></h2><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!JA8h!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a6e3259-403a-434d-b475-97fec18ffa2b_1456x691.gif" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!JA8h!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a6e3259-403a-434d-b475-97fec18ffa2b_1456x691.gif 424w, https://substackcdn.com/image/fetch/$s_!JA8h!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a6e3259-403a-434d-b475-97fec18ffa2b_1456x691.gif 848w, https://substackcdn.com/image/fetch/$s_!JA8h!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a6e3259-403a-434d-b475-97fec18ffa2b_1456x691.gif 1272w, https://substackcdn.com/image/fetch/$s_!JA8h!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a6e3259-403a-434d-b475-97fec18ffa2b_1456x691.gif 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!JA8h!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a6e3259-403a-434d-b475-97fec18ffa2b_1456x691.gif" width="1456" height="691" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9a6e3259-403a-434d-b475-97fec18ffa2b_1456x691.gif&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:691,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:470263,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/gif&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!JA8h!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a6e3259-403a-434d-b475-97fec18ffa2b_1456x691.gif 424w, https://substackcdn.com/image/fetch/$s_!JA8h!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a6e3259-403a-434d-b475-97fec18ffa2b_1456x691.gif 848w, https://substackcdn.com/image/fetch/$s_!JA8h!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a6e3259-403a-434d-b475-97fec18ffa2b_1456x691.gif 1272w, https://substackcdn.com/image/fetch/$s_!JA8h!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a6e3259-403a-434d-b475-97fec18ffa2b_1456x691.gif 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p></p><p>Les profilers d&#233;terministes, tels que <strong>cProfile</strong>, tracent et mesurent tous les appels de toutes les fonctions. Cette approche fournit des donn&#233;es d&#233;taill&#233;es sur chaque fonction appel&#233;e.</p><p>Nous pouvons avoir plusieurs informations gr&#226;ce &#224; ce type de profiling : </p><ul><li><p><strong>Nombre d'appels (ncalls) :</strong> cProfile affiche le nombre total d'appels pour chaque fonction sous la colonne 'ncalls'. Cela inclut les appels directs et r&#233;cursifs.</p></li><li><p><strong>Temps total par fonction (cumtime) :</strong> Sous la colonne 'cumtime', cProfile indique le temps cumulatif pass&#233; dans la fonction et toutes les fonctions qu'elle appelle.</p></li><li><p><strong>Temps propre par fonction (tottime) :</strong> Le temps propre, indiqu&#233; dans la colonne 'tottime', repr&#233;sente le temps pass&#233; uniquement dans la fonction elle-m&#234;me, excluant le temps pass&#233; dans les fonctions appel&#233;es.</p></li><li><p><strong>Appels r&#233;cursifs (ncalls) :</strong> Les appels r&#233;cursifs sont &#233;galement inclus dans 'ncalls'. Les appels r&#233;cursifs sont souvent indiqu&#233;s sous une forme '3/1', o&#249; le premier nombre est le nombre total d'appels et le second le nombre d'appels r&#233;cursifs distincts.</p></li><li><p><strong>Ordre d'appel :</strong> L'ordre d'appel n'est pas directement visible dans les rapports standards de cProfile, mais des outils de visualisation tel que SnakeViz peuvent &#234;tre utilis&#233;s pour voir l'ordre d'appel des fonctions.</p></li></ul><p></p><p>Bien que le profiler puisse introduire un certain <strong>overhead</strong>, il reste utile pour l'identification des bottlenecks dans les programmes. Nous combinons souvent cProfile avec d'autres outils, comme des outils de visualisation pour interpr&#233;ter les r&#233;sultats si jamais le profiling est complexe.</p><p></p><h2>L&#8217;overhead, qu&#232;saco ?</h2><blockquote><p><em>L'overhead, en profiling, est le co&#251;t suppl&#233;mentaire en termes de performance que votre programme doit supporter lorsqu'il est analys&#233; par un profiler. </em></p><p><em>Prenons un exemple concret : si vous utilisez un profiler d&#233;terministe comme cProfile en Python, il va enregistrer des d&#233;tails sur chaque appel de fonction et chaque op&#233;ration dans votre programme. </em></p><p><em>Bien que cette information soit pr&#233;cieuse pour l'optimisation,<strong> le processus d'enregistrement lui-m&#234;me n&#233;cessite des ressources suppl&#233;mentaires</strong> - utilisation suppl&#233;mentaire du processeur, consommation de m&#233;moire, etc.</em></p><p><em>Cela signifie que votre programme, lorsqu'il est profil&#233;, va probablement <strong>s'ex&#233;cuter plus lentement</strong> et utiliser plus de ressources qu'en temps normal. </em></p><p><em>Ce ralentissement et cette consommation accrue sont ce qu'on appelle <strong>l'overhead</strong>. Il est important de tenir compte de cet overhead lors de l'analyse des r&#233;sultats du profiler, car <strong>il peut fausser la perception des performances</strong> r&#233;elles du programme.</em></p><p><em>En bref, il est important de prendre en compte que l'overhead repr&#233;sente le co&#251;t en performance d&#251; au processus de profiling lui-m&#234;me.</em></p></blockquote><p></p><h2><strong>1.2) Statistical Profilers</strong></h2><p>Les profilers statistiques, comme <strong>py-spy</strong> ou <strong>pyinstrument</strong>, adoptent une approche diff&#233;rente. Plut&#244;t que d'enregistrer chaque appel de fonction, ils enregistrent la <strong>call stack &#224; intervalles r&#233;guliers</strong>. Cette m&#233;thode g&#233;n&#232;re <strong>moins d'overhead</strong>, ce qui est avantageux pour les applications en production o&#249; minimiser l'impact sur les performances est crucial.</p><p></p><p>La call stack est une structure de donn&#233;es qui permet de stocker des informations sur les instructions de notre programme qui sont en cours d&#8217;execution. <br>Plus d&#8217;informations <a href="https://en.wikipedia.org/wiki/Call_stack">ici</a></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Bx-9!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e0442d1-a6f7-4f9c-976f-cbdbbf48cc73_2800x2000.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Bx-9!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e0442d1-a6f7-4f9c-976f-cbdbbf48cc73_2800x2000.png 424w, https://substackcdn.com/image/fetch/$s_!Bx-9!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e0442d1-a6f7-4f9c-976f-cbdbbf48cc73_2800x2000.png 848w, https://substackcdn.com/image/fetch/$s_!Bx-9!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e0442d1-a6f7-4f9c-976f-cbdbbf48cc73_2800x2000.png 1272w, https://substackcdn.com/image/fetch/$s_!Bx-9!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e0442d1-a6f7-4f9c-976f-cbdbbf48cc73_2800x2000.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Bx-9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e0442d1-a6f7-4f9c-976f-cbdbbf48cc73_2800x2000.png" width="1456" height="1040" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4e0442d1-a6f7-4f9c-976f-cbdbbf48cc73_2800x2000.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1040,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:370784,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Bx-9!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e0442d1-a6f7-4f9c-976f-cbdbbf48cc73_2800x2000.png 424w, https://substackcdn.com/image/fetch/$s_!Bx-9!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e0442d1-a6f7-4f9c-976f-cbdbbf48cc73_2800x2000.png 848w, https://substackcdn.com/image/fetch/$s_!Bx-9!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e0442d1-a6f7-4f9c-976f-cbdbbf48cc73_2800x2000.png 1272w, https://substackcdn.com/image/fetch/$s_!Bx-9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e0442d1-a6f7-4f9c-976f-cbdbbf48cc73_2800x2000.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>Bien que les profilers statistiques fournissent une vue d'ensemble utile, ils peuvent parfois manquer de certains d&#233;tails fins que les profilers d&#233;terministes r&#233;v&#232;lent. </p><p>Ils sont particuli&#232;rement adapt&#233;s pour obtenir un aper&#231;u global des performances d'une application, et pour identifier les zones o&#249; le temps est principalement consacr&#233;.</p><p></p><div><hr></div><p>Si vous appr&#233;ciez la newsletter StuffAndCode, vous pouvez vous inscrire afin de ne manquer aucun article ! </p><p>&#128013; Et recevez en PLUS, un <strong>article exclusif</strong> sur comment profiler n&#8217;importe quel type de code Python.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.stuffandcode.com/subscribe?&quot;,&quot;text&quot;:&quot;Abonnez-vous maintenant&quot;,&quot;action&quot;:null,&quot;class&quot;:&quot;button-wrapper&quot;}" data-component-name="ButtonCreateButton"><a class="button primary button-wrapper" href="https://blog.stuffandcode.com/subscribe?"><span>Abonnez-vous maintenant</span></a></p><div><hr></div><p></p><h1>2) Les mesures de temps </h1><h2><strong>2.1) CPU Time</strong></h2><p>Le CPU time correspond au temps durant lequel le <strong>CPU est occup&#233;</strong> &#224; ex&#233;cuter du code. Par exemple, si vous avez une fonction qui envoie une requ&#234;te &#224; un site web et attend la r&#233;ponse pour renvoyer le HTML, la majeure partie du temps sera pass&#233;e en attente de la r&#233;ponse du site, et non dans l'ex&#233;cution de votre code proprement dit. Ainsi, le CPU time enregistr&#233; sera relativement faible.</p><h2><strong>2.2) Wall Clock Time</strong></h2><p>Le wall clock time, quant &#224; lui, se mesure comme si on le faisait en <strong>regardant une montre</strong>. Il est particuli&#232;rement utile pour &#233;valuer les performances d'applications qui interagissent beaucoup avec d'autres services, ou qui effectuent des appels &#224; des API. Cette mesure permet de d&#233;terminer si la lenteur de l'application est due &#224; votre code ou &#224; l'attente de r&#233;ponses externes.</p><p></p><h2><strong>Exemple : Mesurer le CPU time et le Wall clock time d'un script Python</strong></h2><p>Prenons un script Python basique, <code>dummy.py</code>, qui t&#233;l&#233;charge un gros fichier :</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!weg6!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce682a80-8704-43d0-8593-b962c52b4596_2988x1056.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!weg6!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce682a80-8704-43d0-8593-b962c52b4596_2988x1056.png 424w, https://substackcdn.com/image/fetch/$s_!weg6!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce682a80-8704-43d0-8593-b962c52b4596_2988x1056.png 848w, https://substackcdn.com/image/fetch/$s_!weg6!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce682a80-8704-43d0-8593-b962c52b4596_2988x1056.png 1272w, https://substackcdn.com/image/fetch/$s_!weg6!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce682a80-8704-43d0-8593-b962c52b4596_2988x1056.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!weg6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce682a80-8704-43d0-8593-b962c52b4596_2988x1056.png" width="1456" height="515" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ce682a80-8704-43d0-8593-b962c52b4596_2988x1056.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:515,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:231182,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!weg6!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce682a80-8704-43d0-8593-b962c52b4596_2988x1056.png 424w, https://substackcdn.com/image/fetch/$s_!weg6!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce682a80-8704-43d0-8593-b962c52b4596_2988x1056.png 848w, https://substackcdn.com/image/fetch/$s_!weg6!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce682a80-8704-43d0-8593-b962c52b4596_2988x1056.png 1272w, https://substackcdn.com/image/fetch/$s_!weg6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce682a80-8704-43d0-8593-b962c52b4596_2988x1056.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Nous pouvons mesurer le CPU time et le Wall clock time avec la commande Linux <code>time</code>.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Zdbo!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a1a6edb-3026-4651-a702-d1d525a46c02_2988x600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Zdbo!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a1a6edb-3026-4651-a702-d1d525a46c02_2988x600.png 424w, https://substackcdn.com/image/fetch/$s_!Zdbo!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a1a6edb-3026-4651-a702-d1d525a46c02_2988x600.png 848w, https://substackcdn.com/image/fetch/$s_!Zdbo!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a1a6edb-3026-4651-a702-d1d525a46c02_2988x600.png 1272w, https://substackcdn.com/image/fetch/$s_!Zdbo!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a1a6edb-3026-4651-a702-d1d525a46c02_2988x600.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Zdbo!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a1a6edb-3026-4651-a702-d1d525a46c02_2988x600.png" width="1456" height="292" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1a1a6edb-3026-4651-a702-d1d525a46c02_2988x600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:292,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:133448,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Zdbo!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a1a6edb-3026-4651-a702-d1d525a46c02_2988x600.png 424w, https://substackcdn.com/image/fetch/$s_!Zdbo!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a1a6edb-3026-4651-a702-d1d525a46c02_2988x600.png 848w, https://substackcdn.com/image/fetch/$s_!Zdbo!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a1a6edb-3026-4651-a702-d1d525a46c02_2988x600.png 1272w, https://substackcdn.com/image/fetch/$s_!Zdbo!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a1a6edb-3026-4651-a702-d1d525a46c02_2988x600.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p></p><p>Ici, <strong>real</strong> repr&#233;sente le temps total &#233;coul&#233; depuis le lancement jusqu'&#224; la fin de l'ex&#233;cution du script (Wall clock time). </p><p><strong>User</strong> est le CPU time utilis&#233; par le processus utilisateur (User CPU time). </p><p><strong>Sys</strong> indique le CPU time utilis&#233; par le syst&#232;me pour des t&#226;ches au niveau du kernel, telles que l'&#233;criture de fichiers ou l'allocation de m&#233;moire. Plus de d&#233;tail sur cette r&#233;ponse de StackOverflow : </p><p><a href="https://stackoverflow.com/questions/556405/what-do-real-user-and-sys-mean-in-the-output-of-time1">Explication real, user, sys de la commande time</a></p><p>Dans cet exemple, la majorit&#233; du temps est consacr&#233;e &#224; a<strong>ttendre la r&#233;ponse du serveur </strong>(I/O), plut&#244;t qu'&#224; l'utilisation du CPU. Sur35 secondes environ d'ex&#233;cution du script, seulement 2.6 secondes environ (user + sys) sont consacr&#233;es &#224; des t&#226;ches CPU. Cela indique que pour optimiser ce code, il faudrait se concentrer principalement sur la partie r&#233;seau.</p><p></p><h2>Les r&#233;sultats </h2><p><br>Nous allons profiler un script tr&#232;s simple afin de montrer les r&#233;sultats que nous pouvons obtenir avec <strong>cProfile</strong> et <strong>pyinstrument</strong>, pour pr&#233;senter un cas concret et expliquer comment interpr&#233;ter les r&#233;sultats. <br><br>Voici le code en question, une boucle avec des prints et un <code>time.sleep</code>. </p><p>Quelque chose de simple mais qui va pouvoir illustrer nos propos.</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!AADG!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b0825a7-bf9d-4564-ae66-c1cbd17006b7_1608x1384.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!AADG!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b0825a7-bf9d-4564-ae66-c1cbd17006b7_1608x1384.png 424w, https://substackcdn.com/image/fetch/$s_!AADG!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b0825a7-bf9d-4564-ae66-c1cbd17006b7_1608x1384.png 848w, https://substackcdn.com/image/fetch/$s_!AADG!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b0825a7-bf9d-4564-ae66-c1cbd17006b7_1608x1384.png 1272w, https://substackcdn.com/image/fetch/$s_!AADG!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b0825a7-bf9d-4564-ae66-c1cbd17006b7_1608x1384.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!AADG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b0825a7-bf9d-4564-ae66-c1cbd17006b7_1608x1384.png" width="1456" height="1253" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5b0825a7-bf9d-4564-ae66-c1cbd17006b7_1608x1384.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1253,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:146309,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!AADG!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b0825a7-bf9d-4564-ae66-c1cbd17006b7_1608x1384.png 424w, https://substackcdn.com/image/fetch/$s_!AADG!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b0825a7-bf9d-4564-ae66-c1cbd17006b7_1608x1384.png 848w, https://substackcdn.com/image/fetch/$s_!AADG!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b0825a7-bf9d-4564-ae66-c1cbd17006b7_1608x1384.png 1272w, https://substackcdn.com/image/fetch/$s_!AADG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b0825a7-bf9d-4564-ae66-c1cbd17006b7_1608x1384.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><h2>cProfile</h2><p></p><p>Afin de profiler notre programme, nous pouvons utiliser la commande suivante :</p><p><code>python -m cProfile -s cumtime &nbsp;some_script.py<br></code></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Qcqe!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff9b169ff-a576-40ca-bfb7-126066264053_2910x866.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Qcqe!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff9b169ff-a576-40ca-bfb7-126066264053_2910x866.png 424w, https://substackcdn.com/image/fetch/$s_!Qcqe!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff9b169ff-a576-40ca-bfb7-126066264053_2910x866.png 848w, https://substackcdn.com/image/fetch/$s_!Qcqe!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff9b169ff-a576-40ca-bfb7-126066264053_2910x866.png 1272w, https://substackcdn.com/image/fetch/$s_!Qcqe!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff9b169ff-a576-40ca-bfb7-126066264053_2910x866.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Qcqe!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff9b169ff-a576-40ca-bfb7-126066264053_2910x866.png" width="1456" height="433" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f9b169ff-a576-40ca-bfb7-126066264053_2910x866.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:433,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:371668,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Qcqe!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff9b169ff-a576-40ca-bfb7-126066264053_2910x866.png 424w, https://substackcdn.com/image/fetch/$s_!Qcqe!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff9b169ff-a576-40ca-bfb7-126066264053_2910x866.png 848w, https://substackcdn.com/image/fetch/$s_!Qcqe!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff9b169ff-a576-40ca-bfb7-126066264053_2910x866.png 1272w, https://substackcdn.com/image/fetch/$s_!Qcqe!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff9b169ff-a576-40ca-bfb7-126066264053_2910x866.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>Nous pouvons voir que le script prend 1 seconde, donc ceci est un <strong>wall clock time</strong> ainsi que les endroits qui prennent le plus de temps. Par exemple, nous pouvons voir que <code>time.sleep</code> est la m&#233;thode qui prend le plus de temps (cf. la colonne <code>tottime</code>).</p><p>Aussi, nous pouvons observer que la fonction <code>print</code> a &#233;t&#233; appel&#233;e 10 fois. Nous pouvons changer l&#8217;ordre de cet output en fonction de ce que nous voulons examiner.</p><p>Nous pouvons &#233;galement utiliser des outils de visualisation afin d&#8217;avoir un rendu plus graphique, mais ce n&#8217;est pas l&#8217;objet de cet article.</p><p></p><h2>PyInstrument</h2><p></p><p>Passons maintenant &#224; pyinstrument. Pour l&#8217;installer, vous pouvez executer la commande :</p><p><code>pip install pyinstrument  </code></p><p>et puis commencer le profiling :</p><p><code>pyinstrument some_script.py</code></p><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!AUf4!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F253ea006-6ff1-4639-b1dc-a9f9cc32d5ae_2904x818.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!AUf4!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F253ea006-6ff1-4639-b1dc-a9f9cc32d5ae_2904x818.png 424w, https://substackcdn.com/image/fetch/$s_!AUf4!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F253ea006-6ff1-4639-b1dc-a9f9cc32d5ae_2904x818.png 848w, https://substackcdn.com/image/fetch/$s_!AUf4!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F253ea006-6ff1-4639-b1dc-a9f9cc32d5ae_2904x818.png 1272w, https://substackcdn.com/image/fetch/$s_!AUf4!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F253ea006-6ff1-4639-b1dc-a9f9cc32d5ae_2904x818.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!AUf4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F253ea006-6ff1-4639-b1dc-a9f9cc32d5ae_2904x818.png" width="1456" height="410" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/253ea006-6ff1-4639-b1dc-a9f9cc32d5ae_2904x818.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:410,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:240875,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!AUf4!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F253ea006-6ff1-4639-b1dc-a9f9cc32d5ae_2904x818.png 424w, https://substackcdn.com/image/fetch/$s_!AUf4!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F253ea006-6ff1-4639-b1dc-a9f9cc32d5ae_2904x818.png 848w, https://substackcdn.com/image/fetch/$s_!AUf4!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F253ea006-6ff1-4639-b1dc-a9f9cc32d5ae_2904x818.png 1272w, https://substackcdn.com/image/fetch/$s_!AUf4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F253ea006-6ff1-4639-b1dc-a9f9cc32d5ae_2904x818.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><br>Sur ce screenshot, nous pouvons constater plusieurs choses : </p><ul><li><p>tout d'abord, nous avons la dur&#233;e qui est le <strong>wall clock time</strong> ainsi que le <strong>CPU time</strong>. </p></li><li><p>Nous pouvons &#233;galement remarquer que le CPU time est vraiment tr&#232;s court compar&#233; au wall clock time, ce qui signifie que le <strong>CPU a &#233;t&#233; en attente</strong> pendant la quasi-totalit&#233; du programme.</p></li></ul><p>Enfin, nous pouvons visualiser les m&#233;thodes qui prennent le plus de temps sous forme d&#8217;arbre, c&#8217;est assez pratique. Il peut y avoir plusieurs branches qui indiquent ce qui prend le plus de temps et permettent de savoir l&#8217;origine de l&#8217;appel.</p><p></p><h1>Quizz Time </h1><p>Je trouve qu&#8217;il est toujours pertinent de se rem&#233;morer ce qu'on vient de lire, pour v&#233;rifier si l&#8217;on a vraiment retenu quelque chose. </p><p>Voici quelques questions :</p><ul><li><p>Quels sont les diff&#233;rents types de profilers ?</p></li><li><p>Quelles sont leurs diff&#233;rences ?</p></li><li><p>Pouvez-vous nommer un profiler de chaque type ?</p></li><li><p>Quelle est la diff&#233;rence entre wall clock time et CPU time ?</p><p></p></li></ul><p>Si vous avez tout juste, vous avez compris l'essentiel de cet article, bien jou&#233; ! </p><p></p><div><hr></div><p>Si vous appr&#233;ciez la newsletter StuffAndCode, vous pouvez vous inscrire afin de ne manquer aucun article ! </p><p>&#128013; Et recevez en PLUS, un <strong>article exclusif</strong> sur comment profiler n&#8217;importe quel type de code Python.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.stuffandcode.com/subscribe?&quot;,&quot;text&quot;:&quot;Abonnez-vous maintenant&quot;,&quot;action&quot;:null,&quot;class&quot;:&quot;button-wrapper&quot;}" data-component-name="ButtonCreateButton"><a class="button primary button-wrapper" href="https://blog.stuffandcode.com/subscribe?"><span>Abonnez-vous maintenant</span></a></p><div><hr></div><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.stuffandcode.com/subscribe?&quot;,&quot;text&quot;:&quot;S'abonner&quot;,&quot;language&quot;:&quot;fr&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">StuffAndCode Newsletter est une publication soutenue par ses lecteurs. Pour recevoir de nouveaux posts et soutenir mon travail, envisagez de devenir un abonn&#233; gratuit ou payant.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Tapez votre e-mail&#8230;" tabindex="-1"><input type="submit" class="button primary" value="S'abonner"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item></channel></rss>