[Mono-bugs] [Bug 52395][Wis] New - System.Buffer.BlockCopy is slower than System.Array.Copy
bugzilla-daemon@bugzilla.ximian.com
bugzilla-daemon@bugzilla.ximian.com
Fri, 9 Jan 2004 09:53:15 -0500 (EST)
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by vargaz@freemail.hu.
http://bugzilla.ximian.com/show_bug.cgi?id=52395
--- shadow/52395 2004-01-09 09:53:15.000000000 -0500
+++ shadow/52395.tmp.9093 2004-01-09 09:53:15.000000000 -0500
@@ -0,0 +1,76 @@
+Bug#: 52395
+Product: Mono/Runtime
+Version: unspecified
+OS: unknown
+OS Details:
+Status: NEW
+Resolution:
+Severity: Unknown
+Priority: Wishlist
+Component: misc
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: bmaurer@users.sf.net
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: System.Buffer.BlockCopy is slower than System.Array.Copy
+
+Description of Problem:
+According to MSDN:
+"[The System.Buffer] class provides better performance for manipulating
+primitive types than similar methods in the Array class."
+
+However, on Mono, it is actually the other way around. This can have
+serious performance implications for trying to optimize code.
+
+Steps to reproduce the problem:
+class T {
+ const int sz = 128;
+ static void Main () {
+ byte [] src = new byte [sz];
+ byte [] dst = new byte [sz];
+
+ for (int i = 0; i < 10000000; i++) {
+#if BUFFER
+ System.Buffer.BlockCopy
+#else
+ System.Array.Copy
+#endif
+ (src, 0, dst, 0, sz);
+ }
+ }
+}
+
+Actual Results:
+[benm@Ben tmp]$ mcs bytebuff.cs /d:BUFFER /out:buffer.exe; mcs bytebuff.cs
+/out:arraycopy.exe
+[benm@Ben tmp]$ time mono buffer.exe ; time mono arraycopy.exe
+
+real 0m15.677s
+user 0m6.630s
+sys 0m0.150s
+
+real 0m7.572s
+user 0m3.280s
+sys 0m0.060s
+
+
+Expected Results:
+The Buffer version should be as fast as, or preferably faster than, the
+Array version
+
+How often does this happen?
+Always
+
+Additional Information:
+I tested this on MS windows and by eye, the performance was better with the
+Buffer version (there is sadly no timer on Windows, so I wasnt able to
+tell). However, there was not a visiable gap as in Mono.
+
+------- Additional Comments From vargaz@freemail.hu 2004-01-09 09:53 -------
+Actually, the two copy methods have the same performance, since each
+one uses memcpy. BlockCopy is slower because it contains three internal
+calls (for argument checking) while Array.Copy contains only one. If you
+ change 128 to 1280 (so copying time dominates), the two methods have
+approx the same performance.