Rust Performance and Optimization Quiz

Rust
0 Passed
0% acceptance

Master advanced performance techniques in Rust including profiling, benchmarking, memory optimization, and compiler optimizations

40 Questions
~80 minutes
1

Question 1

What is the default optimization level in Cargo?

A
Debug mode: no optimizations, development focused
B
Release mode: -O3 equivalent optimizations
C
Always optimized
D
No default level
2

Question 2

What does cargo build --release do?

A
Enables aggressive optimizations, slower compilation
B
Makes release build
C
Strips debug info
D
No special optimizations
3

Question 3

What is the criterion crate used for?

A
Statistical benchmarking with proper warmup and measurement
B
Code criteria
C
Performance criteria
D
Criterion doesn't exist
4

Question 4

What is profiling in Rust?

A
Measuring where time is spent in code using tools like perf, flamegraph
B
Code analysis
C
Performance analysis
D
Profiling doesn't exist
5

Question 5

What is cache-friendly code?

A
Code that maximizes cache hits by accessing memory sequentially
B
Fast code
C
Memory efficient code
D
Cache-friendly doesn't exist
6

Question 6

What is loop unrolling?

A
Compiler optimization duplicating loop body to reduce overhead
B
Loop optimization
C
Unrolling loops
D
Loop unrolling doesn't exist
7

Question 7

What is inlining?

A
Replacing function call with function body to eliminate call overhead
B
Function optimization
C
Call elimination
D
Inlining doesn't exist
8

Question 8

What is dead code elimination?

A
Removing unreachable code and unused functions/variables
B
Code cleanup
C
Optimization
D
Dead code elimination doesn't exist
9

Question 9

What is memory alignment?

A
Placing data at addresses that are multiples of data size
B
Memory organization
C
Data alignment
D
Memory alignment doesn't exist
10

Question 10

What is SIMD?

A
Single Instruction Multiple Data - processing multiple values simultaneously
B
Fast processing
C
Vector processing
D
SIMD doesn't exist
11

Question 11

What is branch prediction?

A
CPU guessing which branch will be taken to prefetch instructions
B
Branch optimization
C
Prediction algorithm
D
Branch prediction doesn't exist
12

Question 12

What is data-oriented design?

A
Organizing data for efficient access patterns rather than object-oriented design
B
Data design
C
Efficient design
D
Data-oriented design doesn't exist
13

Question 13

What is the cost of dynamic dispatch?

A
Vtable lookup prevents inlining and optimization
B
Runtime cost
C
Performance cost
D
No cost
14

Question 14

What is heap allocation overhead?

A
Memory allocator bookkeeping and potential cache misses
B
Allocation cost
C
Memory cost
D
No overhead
15

Question 15

What is object pooling?

A
Reusing objects instead of allocating/deallocating frequently
B
Object management
C
Memory pooling
D
Object pooling doesn't exist
16

Question 16

What is the optimizing compiler?

A
LLVM provides most optimizations, rustc applies Rust-specific ones
B
Rust compiler
C
Optimization tool
D
No optimizing compiler
17

Question 17

What is link-time optimization (LTO)?

A
Optimizations that work across crate boundaries
B
Link optimization
C
Cross-crate optimization
D
LTO doesn't exist
18

Question 18

What is codegen-units?

A
Number of parallel code generation units, affects optimization
B
Code units
C
Generation units
D
Codegen-units doesn't exist
19

Question 19

What is panic = "abort"?

A
Aborts process on panic instead of unwinding, smaller binaries
B
Panic handling
C
Error handling
D
panic = "abort" doesn't exist
20

Question 20

What is the perf tool?

A
Linux profiling tool that shows CPU cycles, cache misses, etc.
B
Performance tool
C
Linux profiler
D
Perf doesn't exist
21

Question 21

What is cachegrind?

A
Valgrind tool that simulates cache behavior
B
Cache tool
C
Memory profiler
D
Cachegrind doesn't exist
22

Question 22

What is heaptrack?

A
Memory profiler that tracks all heap allocations
B
Heap tool
C
Memory tracker
D
Heaptrack doesn't exist
23

Question 23

What is the cost of bounds checking?

A
Array/slice access has bounds check, small performance cost
B
Access cost
C
Safety cost
D
No cost
24

Question 24

What is iterator fusion?

A
Compiler combines multiple iterator operations into single loop
B
Iterator optimization
C
Loop fusion
D
Iterator fusion doesn't exist
25

Question 25

What is enum layout optimization?

A
Rust uses discriminant + max variant size, not sum of all variants
B
Enum optimization
C
Memory layout
D
Enum layout optimization doesn't exist
26

Question 26

What is the small string optimization?

A
String stores small strings inline instead of heap allocation
B
String optimization
C
Memory optimization
D
Small string optimization doesn't exist
27

Question 27

What is copy elision?

A
Compiler eliminates unnecessary copies/moves
B
Copy optimization
C
Move elimination
D
Copy elision doesn't exist
28

Question 28

What is the performance cost of Arc?

A
Atomic operations for reference counting, cache contention
B
Reference counting cost
C
Atomic cost
D
No cost
29

Question 29

What is false sharing?

A
Different threads modifying variables in same cache line, causing invalidation
B
Cache sharing
C
Thread contention
D
False sharing doesn't exist
30

Question 30

What is lock contention?

A
Threads waiting for locks, reducing parallelism
B
Lock performance
C
Thread blocking
D
Lock contention doesn't exist
31

Question 31

What is the memory allocator?

A
jemalloc default on some platforms, system allocator on others
B
Memory manager
C
Allocation system
D
Memory allocator doesn't exist
32

Question 32

What is arena allocation?

A
Bulk allocation of objects with single deallocation
B
Memory arena
C
Bulk allocation
D
Arena allocation doesn't exist
33

Question 33

What is the performance cost of FFI?

A
Function call overhead and data conversion between languages
B
Foreign call cost
C
Interface cost
D
No cost
34

Question 34

What is CPU affinity?

A
Pinning threads to specific CPU cores to improve cache locality
B
CPU optimization
C
Thread pinning
D
CPU affinity doesn't exist
35

Question 35

What is branchless programming?

A
Using arithmetic operations instead of conditionals to avoid branch misprediction
B
Conditional elimination
C
Arithmetic programming
D
Branchless programming doesn't exist
36

Question 36

What is the performance cost of debug assertions?

A
Debug mode has bounds checking and overflow checks that release mode doesn't
B
Assertion cost
C
Debug cost
D
No cost
37

Question 37

What is asymptotic complexity?

A
How algorithm performance scales with input size (Big O notation)
B
Algorithm complexity
C
Performance scaling
D
Asymptotic complexity doesn't exist
38

Question 38

What is Amdahl's law?

A
Maximum speedup limited by serial portion of program
B
Parallel speedup law
C
Performance law
D
Amdahl's law doesn't exist
39

Question 39

What is cache prefetching?

A
CPU loads data into cache before it's needed
B
Cache optimization
C
Data loading
D
Cache prefetching doesn't exist
40

Question 40

In a high-performance Rust application with real-time constraints, complex data structures, and multi-threading, what optimization strategy would you implement?

A
Profile first, optimize algorithms/data structures, use release builds, minimize allocations, avoid locks, use SIMD, cache-friendly layouts, measure continuously
B
Only use --release
C
Add #[inline] everywhere
D
No optimization needed

QUIZZES IN Rust