title: Why is my https getter in Haskell so slow compared to curl?
body: <p>I'm writing a simple https getter code in Haskell. After I get the response I save it to a file with compression. However my version is very slow compared to curl and gzip combination. How can I make it faster that curl? Details are below.</p>
  
  <p>Haskell code (fetcher.hs):</p>
  
  <pre><code>import Control.Lens
  import qualified Codec.Compression.GZip as GZip
  import qualified Data.ByteString.Lazy as BL
  import Network.Wreq
  
  writeURIBodyToFile :: FilePath -&gt; String -&gt; IO()
  writeURIBodyToFile filePath uri = do
    response &lt;- get uri
    let body = (response ^. responseBody)
    BL.writeFile filePath (GZip.compress body)
  
  main :: IO ()
  main = writeURIBodyToFile "out.html.gz" "https://www.sahibinden.com/ilan/vasita-otomobil-seat-hatasiz-boyasiz-tramersiz-dsg-leon-469484363/detay/"
  </code></pre>
  
  <p>Haskell result:</p>
  
  <pre><code>$ ghc -o fetcher fetcher.hs
  $ time ./fetcher 
  
  real    0m9.240s
  user    0m8.840s
  sys     0m0.232s
  </code></pre>
  
  <p>curl result:</p>
  
  <pre><code>$ time curl "https://www.sahibinden.com/ilan/vasita-otomobil-seat-hatasiz-boyasiz-tramersiz-dsg-leon-469484363/detay/" | gzip &gt; out.html.gz
    % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                   Dload  Upload   Total   Spent    Left  Speed
  100  102k  100  102k    0     0   331k      0 --:--:-- --:--:-- --:--:--  332k
  
  real    0m0.524s
  user    0m0.156s
  sys     0m0.040s
  </code></pre>
  
  <p>Edit:
  I also tried with http-conduit package, nothing changed.</p>
  
  <pre><code>import qualified Data.ByteString.Lazy as BL
  import           Network.HTTP.Simple
  
  main :: IO ()
  main = do
      response &lt;- httpLBS "https://www.sahibinden.com/ilan/vasita-otomobil-seat-hatasiz-boyasiz-tramersiz-dsg-leon-469484363/detay/"
      BL.writeFile "outnew.html" $ getResponseBody response
  </code></pre>
  
  <p>Edit2: I also checked the connection with tcpdump, and there is no connection issue.</p>
  
  <p>Edit3: <code>GHCi, version 7.10.3</code></p>
  
  <p>Edit4: compile command <code>ghc -o fetcher fetcher.hs</code></p>
  
  <p>Edit5: the problem couldn't be reproducible with this code on Feb 2019:</p>
  
  <pre><code>{-# LANGUAGE OverloadedStrings #-}
  import Network.HTTP.Simple
  import qualified Data.ByteString.Char8 as B8
  
  main :: IO ()
  main = httpBS "https://www.sahibinden.com/ilan/vasita-otomobil-mercedes-benz-mercedes-benz-c-180-fascination-7g-tronic-ozel-renk-652750468/detay" &gt;&gt;= B8.putStrLn . getResponseBody
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code>$ ghc -o fetcher fetcher.hs
  $ time ./fetcher 
  real    0m0,549s
  user    0m0,093s
  sys     0m0,021s
  </code></pre>
  
  <p>Edit6: again, the problem couldn't be reproducible on the first code sample on Feb 2019 <code>GHCi, version 8.0.2</code></p>