# Optimization level setting (-O / --optimize)

**URL:** <https://discourse.julialang.org/t/optimization-level-setting-o-optimize/95809>\
**Category:** General Usage\
**Tags:** potential-bug, cli\
**Created:** [March 9, 2023, 4:20pm UTC](https://discourse.julialang.org/t/optimization-level-setting-o-optimize/95809 "2023-03-09T16:20:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![airpmb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/airpmb/32/7826_2.png) [@airpmb](https://discourse.julialang.org/u/airpmb)\
**Post date:** [March 9, 2023, 4:20pm UTC](https://discourse.julialang.org/t/optimization-level-setting-o-optimize/95809/1 "2023-03-09T16:20:10Z")

</div>

Couple of questions regarding this.

First, is there a good way to determine inside the Julia session what the current setting of the optimization level is?

Second, is there some reason this behavior is correct?

```julia
$ julia -O # no error

$ julia --optimize -t auto # no error

$ julia -t auto -O # no error

$ julia -O1 -t auto # no error

$ julia -O -t auto
ERROR: julia: invalid argument to -O (-t)

$ julia -O -v
ERROR: julia: invalid argument to -O (-v)

```

According to the [docs](https://docs.julialang.org/en/v1/manual/command-line-options/#Command-line-switches-for-Julia),

> `-O`, `--optimize={0,1,2*,3}` Set the optimization level (level is 3 if `-O` is used without a level)

… it seems that the bit about `-O` being used without a level only works if it is the last argument.

The same kind of thing happens with the `-g` flag

```julia
$ julia -g -t auto
ERROR: julia: invalid argument to -g (-t)

```

---

<div class="post-metadata">

**Author:** ![ffevotte](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffevotte/32/6587_2.png) [@ffevotte](https://discourse.julialang.org/u/ffevotte)\
**Post date:** [March 9, 2023, 4:38pm UTC](https://discourse.julialang.org/t/optimization-level-setting-o-optimize/95809/2 "2023-03-09T16:38:38Z")

</div>

> [@airpmb](#):
>
> First, is there a good way to determine inside the Julia session what the current setting of the optimization level is?

It’s probably not part of the public API, but I think `Base.JLOptions().opt_level` gives you that information.

```julia
shell$ julia -e 'println(Base.JLOptions().opt_level)'
2
shell$ julia -O3 -e 'println(Base.JLOptions().opt_level)'                                                                                
3

```
