# What's a \[good\] way to make slow Julia code (with no side-effects)?

**URL:** <https://discourse.julialang.org/t/whats-a-good-way-to-make-slow-julia-code-with-no-side-effects/1341>\
**Category:** General Usage\
**Created:** [January 7, 2017, 2:37pm UTC](https://discourse.julialang.org/t/whats-a-good-way-to-make-slow-julia-code-with-no-side-effects/1341 "2017-01-07T14:37:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [January 7, 2017, 2:37pm UTC](https://discourse.julialang.org/t/whats-a-good-way-to-make-slow-julia-code-with-no-side-effects/1341/1 "2017-01-07T14:37:25Z")

</div>

[I was trying to prove to myself that left side of && is always run (unnecessarily, when right one hard-coded to return false).]

slow(n) = begin for i in 1:n end; return true end # Gets optimized away, Julia scores points.

[In theory, functions without side-effects, always returning same, should ALWAYS be dead-code eliminated; good for Julia if guaranteed.]

sleep(n) doesn’t work (for me), as it has side-effects.

```julia
julia> slow(n) = begin rand(n); return true end # This actually has side-effects.. could have used /dev/random ..

julia> if slow(1000000000) && false println("Dummy hello") end
ERROR: OutOfMemoryError()
 in rand at ./random.jl:300 [inlined]
 in rand at ./random.jl:297 [inlined]
 in rand at ./random.jl:229 [inlined]
 in rand at ./random.jl:230 [inlined]
 in slow(::Int64) at ./REPL[71]:1

julia> if sleep(1) && false println("Preferably wouldn't happen..; nor should it run sleep that doesn't return bool before finding out.") end
ERROR: TypeError: non-boolean (Void) used in boolean context

julia> fib(10) # I thought in Base..
ERROR: UndefVarError: fib not defined

julia> fibonacci(10)
ERROR: UndefVarError: fibonacci not defined

help?> ⊊ # just noticed, what is it, doc doesn't explain; diff from ⊈ that I know what is..

```

---

<div class="post-metadata">

**Author:** ![fengyang.wang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fengyang.wang/32/104_2.png) [@fengyang.wang](https://discourse.julialang.org/u/fengyang.wang)\
**Post date:** [April 2, 2017, 2:11am UTC](https://discourse.julialang.org/t/whats-a-good-way-to-make-slow-julia-code-with-no-side-effects/1341/2 "2017-04-02T02:11:24Z")

</div>

Only expressions that are known to be effect-free can be optimized out on the left hand side of `&&`. Furthermore, the compiler currently doesn’t always do this optimization, even when effect-free is known (such as when a `Base.@pure` annotation exists.)

As for ⊊, this is mathematical notation for [proper subset](http://mathworld.wolfram.com/ProperSubset.html) which is as you noted a distinct concept from “not a subset” (⊈). You are right that the difference does not seem to be documented.
