Developer Martin Finkel conducted a performance comparison between C and C# by porting a specific video filter—the Gaussian blur—from the VLC media player. The experiment aimed to determine if C#'s managed nature and garbage collector would significantly hinder performance compared to C, which is the native language of VLC. To ensure a fair comparison, Finkel created a line-by-line C# port that used the same loops, integer math, and raw pointers as the original C implementation. The C# version was compiled using .NET Native AOT, allowing it to run as a native DLL plugin within VLC.

A side-by-side comparison of an original frame and the same frame blurred with different sigma values.
Visual examples of the Gaussian blur filter applied at sigma values of 2, 4, and 8.martinfinkel.com

Developer Martin Finkel conducted a performance comparison between C and C# by porting a specific video filter—the Gaussian blur—from the VLC media player.

The initial results showed a clear performance gap: the C# port took approximately 23% longer per frame than the original C code. Analysis of the machine code revealed that the .NET RyuJIT compiler emitted more instructions than the Clang compiler, specifically by recomputing loop bounds and keeping sums in memory rather than registers. However, by making two small adjustments—hoisting loop bounds into local variables and using `nint` for indices to avoid 32-to-64-bit conversions—the C# port's performance improved to within 8% of the C version. This demonstrated that much of the performance delta was attributable to how the compiler handled specific C# constructs rather than inherent language limitations.

A performance comparison chart showing frames per second for the C# port versus the current VLC implementation.
Initial performance results showing the C# port running at 6.4 FPS compared to the original VLC implementation at 7.9 FPS.martinfinkel.com

The initial results showed a clear performance gap where the C# port took approximately 23% longer per frame than the original C code.

In subsequent rounds of optimization, both versions were improved using algorithmic refinements such as replacing division with multiplication, optimizing memory access patterns, and utilizing the symmetry of the Gaussian bell curve. In the final 'tuned' round, both versions utilized AVX2 SIMD instructions to achieve massive speedups, with the C# version performing nearly on par with C. Finkel concluded that while C remains the superior choice for the final 10% of performance, C# is a highly viable and productive choice for CPU-bound VLC plugins, provided developers account for the specific ways the .NET compiler optimizes their code. The experiment was conducted on a 1080p clip using an 11th-gen Intel Core i7 processor.

A performance comparison chart showing optimized C and C# versions against the original VLC implementation.
Performance results after the first round of optimizations, showing significant speedups for both C and C# versions.martinfinkel.com

In subsequent rounds of optimization, both versions were improved using algorithmic refinements such as replacing division with multiplication.

A performance comparison chart showing the final tuned C and C# versions achieving near-parity.
Final tuned results showing the C# version performing nearly on par with the C version using AVX2 SIMD instructions.martinfinkel.com

In the final 'tuned' round, both versions utilized AVX2 SIMD instructions to achieve massive speedups, with the C# version performing nearly on par with C.