last day (15 days later) » 

16:59
1
A: LeetCode: Pascal's Triangle C#

IEatBagelsYou use lists, which are great when you have a flexible number of elements in it and you might add/remove some, but in your case, you know exactly how many elements each list would contain and there is no possibility for it to change. In this case, you are using the wrong data structure because t...

"As I said, the benchmark tool isn't good" indeed: I see only a 6* improvement (slightly worse than Peter's 'best', which is 1.3* quicker than this). I bet you'd get the opposite result if you switched the calls around.
@VisualMelon I've edited my question to use a proper benchmark tool.
Odd that you only get a 2* improvement when you test it... for N=30 I get 12.4μs with the OP's code, and 2.3μs with yours (1.6μs with Peter's Generate_Array_Improved_Reflective). I'll upload my results (and code) including your method once it finishes running properly.
@VisualMelon I don't think this is a 2* improvement, if I understand what you mean properly. The first result is ~9ns, the other is ~18000ns.
Huh, yeah, I can't read. I think your benchmark is broken (can you put the code somewhere?): it would more take 9ns just to compute the last row.
The exact code would be appreciated, with the methods and everything, because I do not believe that result one bit. My code is in this Gist; I'll add the results when it finishes running.
16:59
@VisualMelon I've added the benchmark code. I will also run your gist on my computer to see if the results are different
Your run will probably finish before mine; I've run it twice already but it keeps crashing because my filesystem hates me ;)
@VisualMelon I removed the Jodrell's code because I don't have the right .net version for this, but I'll keep you updated
(So you know, you can find the nice table outputs in the BenchmarkDotNet.Artifacts\results directory)
Thanks for running the benchmarks, I don't know why my results were so weird on my computer
Maybe there's a compiler optimization that was made that made the benchmark act weird
Can you put your exact code somewhere?
17:11
Yeah I'll do that. If I can learn something out of it it's worth it :p
(You can paste it directly into chat if it suits you, it copes pretty well with code dumps, as I recall)
using System;
using BenchmarkDotNet.Attributes;
using System.Runtime;
using System.Runtime.CompilerServices;
using System.Linq;
using System.Collections.Generic;
using BenchmarkDotNet.Running;

namespace SpanVsArray
{
    class Program
    {
        static void Main(string[] args)
        {
            BenchmarkRunner.Run<Bench>();
        }
    }

    [RPlotExporter, RankColumn]
    public class Bench
    {
        [Benchmark]
        public void OP() => OP(33);

        [Benchmark]
        public void Mine() => Mine(33);
Results are : (Mine second, OP first)

Mean Error
20.766 us 0.4133 us
2.545 us 0.0504 us
It's a dumb question, but you ran your analysis in Release mode, right?
Yes; BenchmarkDotNet complains if you run it under release
Under Debug, you mean?
I do yes*
17:24
That's what I thought :p
Is it possible that the differences in benchmark time only come from different environment (maybe my computer is much faster than yours?)
Running your benchmark now...
| OP | 14.784 us | 0.2957 us | 0.2904 us | 2 |
| Mine | 2.694 us | 0.0517 us | 0.0654 us | 1 |
(5.5* faster)
I've got to catch a train and won't be active for the next day or so, but feel free to leave stuff for me to read. You should probably update your answer with your new benchmark, because 9ns is a bit ridiculous ;)
17:39
I will do that, thanks!

last day (15 days later) »