Performance, Debugging, and Metaprogramming
- How is release mode different from debug mode?
That depends on your Cargo configuration. By default, there are several compiler flags that have different default values in release versus debug mode. One such flag is the opt-level that gets sent to the llvm code generation—the default debug opt-level is 2, and the default release opt-level is 3. These defaults can be changed in Cargo.toml
.
- How long will an empty loop take to run?
Test it out. Otherwise, it is hard to say for sure on every platform. loop will always be an infinite loop. while true should maybe also be an infinite loop, but will generate a warning. for _ in 0..99999999 {}
will be removed at opt-level 3 but not opt-level 2.
- What is linear time in Big O notation?
Linear time is O(n) time.
- Name a function that grows faster than exponential growth.
Factorial O(n!) grows faster than exponential growth.
- What is faster, a disk read or a network read?
Measure it. There are many physical factors to consider here.
- How would you return a Result with multiple error conditions?
Rust recommends using enum types to describe multiple error conditions. Being lazy, you could also use the std::any::Any
type.
- What is a token tree?
A token tree is a tree data structure containing tokens. As a result of Rust lexing, (...), [...], and {...} token groups will become their own branches.
- What is an Abstract Syntax Tree?
An abstract syntax tree is like a token tree but it has a strict structure such that only well-formed (Rust) code can be represented by it.
- Why do procedural macros need to be compiled separately?
Procedural macros are written with normal Rust code. To be used in compilation, procedural macros need to have already been compiled.