2 ms·
> Java isn't interpreted Correct. Not sure why you’re being downvoted. Java and C# are JIT’d, but only hotspots are aggressively optimized (at least in C#; no
by colejohnson66 7y ago
> Java isn't interpreted
Correct. Not sure why you’re being downvoted.
Java and C# are JIT’d, but only hotspots are aggressively optimized (at least in C#; not sure about Java). So in short runs, prevectorized C code will run faster, but once the optimizer kicks in (with long runs), they’ll be neck and neck.
Side note: C# also supports AOT compilation with optimization. Not sure about Java
- daxfohl 7y agoC frequently cannot vectorize without explicit hints. This is because with pointer arithmetic, what you're writing to could be within the array you're reading from. So order of operation could matter, and vectorization could break it.
- colejohnson66 7y agoI guess, cause in C#, you can’t have pointers to the middle of an array (when not using `unsafe` code). So I guess one would just check if the arrays’ pointers were equal, and if they aren’t, the arrays don’t overlap. Side note: C# 8’s ranges and indices return an IEnumerable, so I wonder how those vectorize. Can IEnumerable’s even be vectorized?
- daxfohl 7y agoThe only vectorization I'm aware of in C# is the few classes in System.Numerics that are provided specifically for this optimization. In theory, the C# compiler and/or JIT could automatically issue SIMD ops for some array operations, if it could determine that order of operations doesn't matter (as could just about any other language), but I think as a general rule this is too expensive at compile time or runtime to be worth it, and most languages force you to make it explicit. Except a couple languages like FORTRAN and apparently APL. (Though I'd love to be shown wrong in the C# case).