Well, I wrap your expressions into functions

```
function f(n)
s = 0
for i in 1:n
s += i
end
s
end
g(n) = sum(i for i in 1:n)
```

```
julia> @btime f(1_000_000)
1.881 ns (0 allocations: 0 bytes)
500000500000
julia> @btime g(1_000_000)
4.108 ns (0 allocations: 0 bytes)
500000500000
```

```
julia> @code_native f(10)
.text
; special case: if n==0 return 0
testq %rdi, %rdi
jle L32
; general case: n != 0
; this is where the magic happens and the formula is evaluated
leaq -1(%rdi), %rdx
leaq -2(%rdi), %rax
mulxq %rax, %rax, %rcx
shldq $63, %rax, %rcx
leaq (%rcx,%rdi,2), %rax
addq $-1, %rax
retq
L32:
xorl %eax, %eax
retq
nopw %cs:(%rax,%rax)
```

```
julia> @code_native g(10)
... # much longer output, without any `mul`, but with `call`
```