1 usingSystem;2 usingSystem.Collections;3 usingSystem.Collections.Generic;4 usingSystem.Data;5 usingSystem.Diagnostics;6 usingSystem.IO;7 usingSystem.Linq;8 usingSystem.Runtime.InteropServices;9 usingSystem.Threading;Ten usingEmisdata; One usingNewtonsoft.json; A - namespaceClibrary.consoleapp - { the class Program - { - Static voidMain (string[] args) - { + intLen =50000000; - int[] NewArray =New int[Len]; +Stopwatch SW =NewStopwatch (); A int[] Allarray =New int[Len]; at for(inti =0; i < Len; i++) - { -Allarray[i] =i; - } - - SW. Start (); inThread.Sleep ( +); - array.copy (Allarray, NewArray, Len); to SW. Stop (); +Console.WriteLine ("array.copy Execution Time (MS)"+SW. Elapsedmilliseconds); - theArray.clear (NewArray,0, Len); * SW. Restart (); $Thread.Sleep ( +);Panax NotoginsengNewArray = (int[]) Allarray.clone (); - SW. Stop (); theConsole.WriteLine ("Array.clone Execution Time (MS)"+SW. Elapsedmilliseconds); + AArray.clear (NewArray,0, Len); the SW. Restart (); +Thread.Sleep ( +); -Buffer.blockcopy (Allarray,0, NewArray,0, Len); $ SW. Stop (); $Console.WriteLine ("buffer.blockcopy Execution Time (MS)"+SW. Elapsedmilliseconds); - - Console.readkey (); the } - Wuyi the - } Wu -}
Test results:
Visible: Buffer.blockcopy Best Performance
C # array replication performance test