Skip to content

Instantly share code, notes, and snippets.

@jakubfijalkowski
Created January 21, 2016 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakubfijalkowski/3af8cb0f0b0291c0c8ea to your computer and use it in GitHub Desktop.
Save jakubfijalkowski/3af8cb0f0b0291c0c8ea to your computer and use it in GitHub Desktop.
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