Dave is spot on... To give you an example, I ran a benchmark on 10,000 items using 1. Dave's code; 2. a Linq version; 3. a PLinq version. Below is the code:
<Benchmark(Baseline:=True)>
Public Sub Execute()
Dim diffArray = New Long(maxSize - 1 - 1) {}
For i As Integer = 0 To diffArray.Length - 1
diffArray(i) = LongArray(i + 1) - LongArray(i)
Next
End Sub
<Benchmark>
Public Sub ExecuteLinq()
Dim diffArray As Long() = LongArray.Skip(1).[Select](Function(x, i) LongArray(i) - x).ToArray()
End Sub
<Benchmark>
Public Sub ExecutePLinq()
Dim diffArray As Long() = LongArray.Skip(1).[Select](Function(x, i) LongArray(i) - x).AsParallel().AsOrdered().ToArray()
End Sub
And here are the benchmark results:
// * Summary *
BenchmarkDotNet=v0.11.1, OS=Windows 10.0.17134.228 (1803/April2018Update/Redstone4)
Intel Core i7-4980HQ CPU 2.80GHz (Haswell), 1 CPU, 8 logical and 4 physical cores
[Host] : .NET Framework 4.7.2 (CLR 4.0.30319.42000), 32bit LegacyJIT-v4.7.3132.0
DefaultJob : .NET Framework 4.7.2 (CLR 4.0.30319.42000), 32bit LegacyJIT-v4.7.3132.0
Method | Mean | Error | StdDev | Scaled | ScaledSD |
------------- |------------:|----------:|----------:|-------:|---------:|
Execute | 22.02 us | 0.2142 us | 0.2003 us | 1.00 | 0.00 |
ExecuteLinq | 297.39 us | 1.6327 us | 1.5272 us | 13.51 | 0.14 |
ExecutePLinq | 1,210.37 us | 6.4961 us | 5.7586 us | 54.98 | 0.54 |
// * Legends *
Mean : Arithmetic mean of all measurements
Error : Half of 99.9% confidence interval
StdDev : Standard deviation of all measurements
Scaled : Mean(CurrentBenchmark) / Mean(BaselineBenchmark)
ScaledSD : Standard deviation of ratio of distribution of [CurrentBenchmark] and [BaselineBenchmark]
1 us : 1 Microsecond (0.000001 sec)
Hope this helps! :)