This is a simple example how to improve Code Speed according simple RayTracing Example
Step 1: Try Compiler Optimization Levels
Step 2: Improve Mathematical Functions
Step 3: Multithreading
Step 4: Use Simd Instructions
Step 5: Write the Code for GPUs