3 ms·
>> Are these programs benchmarking typical idiomatic Java https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/csharp.html https://benchmarksgam
by CraigJPerry 5y ago
>> Are these programs benchmarking typical idiomatic Java
https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/csharp.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
c# regex redux - 1.42 seconds
java regex redux - 5.31 seconds
Ok... but looking at the code:
https://benchmarksgame-team.pages.debian.net/benchmarksgame/program/regexredux-java-3.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
import java.io.*;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.Map.Entry;
import java.util.function.*;
import java.util.regex.*;
import static java.util.stream.Collectors.*;
...
It's only using vanilla Java features.
c# ?
...
using System.Runtime.InteropServices;
...
Interesting, why does it need that?
[DllImport("pcre2-8", EntryPoint = "pcre2_compile_8", CharSet = CharSet.Ansi)]
extern static IntPtr PcreCompile(string pattern, long length, uint options,
out int errorcode, out long erroroffset, IntPtr ccontext);
[DllImport("pcre2-8", EntryPoint = "pcre2_jit_compile_8", CharSet = CharSet.Ansi)]
extern static int PcreJitCompile(IntPtr code, uint options);
[DllImport("pcre2-8", EntryPoint = "pcre2_jit_match_8", CharSet = CharSet.Ansi)]
extern unsafe static int PcreJitMatch(IntPtr code, byte* subject,
long length, long startoffset, int options, IntPtr match_data, IntPtr mcontext);
[DllImport("pcre2-8", EntryPoint = "pcre2_match_data_create_8", CharSet = CharSet.Ansi)]
extern unsafe static IntPtr PcreMatchDataCreate(uint ovecsize, IntPtr mcontext);
[DllImport("pcre2-8", EntryPoint = "pcre2_get_error_message_8", CharSet = CharSet.Ansi)]
extern unsafe static int PcreGetErrorMessage(int errorcode, StringBuilder buffer, long bufflen);
[DllImport("pcre2-8", EntryPoint = "pcre2_get_ovector_pointer_8", CharSet = CharSet.Ansi)]
extern unsafe static IntPtr PcreGetOvectorPointer(IntPtr match_data);
[DllImport("pcre2-8", EntryPoint = "pcre2_substitute_8", CharSet = CharSet.Ansi)]
extern unsafe static int PcreSubstitute(IntPtr code, byte* subject,
long length, long startoffset, int options, IntPtr match_data, IntPtr mcontext,
byte* replacement, long rlength, byte* outputbuffer, out long outlength);
Aha! It's because the c# impl is really just a wrapper round a native C impl of the problem.
In what world is this a useful comparison?
The fastest "real" c# solution is still faster than the java one though:
c# (real) - 3.1 seconds
https://benchmarksgame-team.pages.debian.net/benchmarksgame/program/regexredux-csharpcore-5.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
- zigzag312 5y agoI agree. That's really not usefull comparision. They should create categories for each benchmark, like: - very naive code (shortest, most readable & easy to write code) - idiomatic code - optimized code without other-language-libs wrappers and without SIMD, single threaded - optimized code without other-language-libs wrappers and without SIMD, multi-threaded - optimized code without other-language-libs wrappers and with SIMD and/or multi-threaded - optimized code with other-language-libs wrappers allowed and any other optimization technique
- igouy 5y agoYou are free to take the data, create whatever categories you want and publish.
- grumpyprole 5y agoI agree it's not a useful comparison. That's why I don't give much weight to statements such as "Java comes on top in every individual category of all the benchmarks".
- igouy 5y ago> In what world is this a useful comparison? In this world where we also compare to C++ programs. In this world where — as you acknowledge — we also compare a C# regex-redux program that does not use a third party library. https://benchmarksgame-team.pages.debian.net/benchmarksgame/program/regexredux-csharpcore-5.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/... > Interesting, why does it need that? 2 out of 10 tasks regex-redux and pidigits accept third-party libraries, the other 8 out of 10 tasks do not.