Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Ridiculous perf difference in almost-the-same F# code
// Version A
let private renderTriangleAlways renderer ctx v1 v2 v3 c =
let ymin', aes = getAEs v1 v2 v3
let mutable ymin = ymin'
for ae1, ae2 in aes do
let ymax = ae1.YMax
for y = ymin to ymax - 1 do
let minX = int (min ae1.X ae2.X)
let maxX = int <| ceil (max ae1.X ae2.X)
for x = minX to maxX do
NativeInterop.NativePtr.set ctx.Context.Pixels (x + y * ctx.Width) c
ae1.X <- ae1.X + ae1.CoeffX
ae2.X <- ae2.X + ae2.CoeffX
ymin <- ymax
// Version B - ~2 times slower
let private renderTriangleZBuffer renderer ctx v1 v2 v3 c =
let ymin', aes = getAEs v1 v2 v3
let mutable ymin = ymin'
for ae1, ae2 in aes do
let ymax = ae1.YMax
for y = ymin to ymax - 1 do
let minX = int (min ae1.X ae2.X)
let maxX = int <| ceil (max ae1.X ae2.X)
for x = minX to maxX do
let idx = y * ctx.Context.Width + x
NativeInterop.NativePtr.set ctx.Context.Pixels idx c
ae1.X <- ae1.X + ae1.CoeffX
ae2.X <- ae2.X + ae2.CoeffX
ymin <- ymax
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.