How to do it...

Start by running the command include("quad.jl"), which defines the following two functions for calculating the desired roots of the quadratic equation:

function quadratic1(a, b, c)    t(s) = (-b + s*sqrt(Δ))/(2a)    a == 0 && error("a must be different than zero")    Δ = Complex(b^2-4*a*c)    t(1), t(-1)endfunction quadratic2(a, b, c)    Δ = Complex(b^2-4*a*c)    t(s) = (-b + s*sqrt(Δ))/(2a)    a == 0 && error("a must be different than zero")    t(1), t(-1)end

Although they seemingly perform the same work, when we benchmark them, it turns out that they have significantly different performance characteristics (you need to have the BenchmarkTools.jl package installed for this code to work; if it is not installed, add it using the commands using Pkg; ...

Get Julia 1.0 Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.