Why is my Haskell code like SWIFT and C?

This is a very simple Haskell code to find all Pythagorean integers from 1 to 200 that satisfy the Pythagorean theorem X ^ 2 = Y ^ 2 Z ^ 2

Haskell:

let l = [1..200]
let pythagoras = [x | x < -l, y <- l, z <- l, x^2 == y^2 + z^2]

It takes 24.1 seconds to complete it,

Quickly:
Use standard loop
0.05 seconds

C:
Use standard loop
0.022 seconds

enter image description here

hope I can Comment...

Why is Haskell so slow compared to C for Fibonacci sequence?

Always make sure you are compiling the code, because interpreting the code is very time-consuming.

This is a very simple Haskell code to find all Pythagorean integers from 1 to 200 that satisfy the Pythagorean theorem X ^ 2 = Y ^ 2 Z ^ 2

Haskell:

let l = [1..200]
let pythagoras = [x | x <- l, y <- l, z <- l, x^2 == y^2 + z^2]

It takes 24.1 seconds to complete it,

Quickly:< br>Use standard loop
0.05 seconds

C:
Use standard loop
0.022 seconds

enter image description here

I hope I can comment...

Why is Haskell so slow compared to C for Fibonacci sequence?

Always make sure you are compiling the code, because interpreting the code is very time consuming.

Leave a Comment

Your email address will not be published.