コード例 #1
0
 public List <Proposal> Lambda()
 {
     return(ProposalBuilder
            .GetInsurances()
            .Where(p => p.InsuranceId == SearchedInsuranceId)
            .ToList());
 }
コード例 #2
0
 public List <Proposal> LinqQuery()
 {
     return((from proposal in ProposalBuilder.GetInsurances()
             where proposal.InsuranceId == SearchedInsuranceId && proposal.NetPremium > SearchedNetPremium
             select proposal)
            .ToList());
 }
コード例 #3
0
        public unsafe ReadOnlyProposal[] ForVectorized()
        {
            ProposalResult p = ProposalBuilder.GetSortedVectorizedInsurances();

            var insuranceId = Vector256.Create(SearchedInsuranceId);

            fixed(int *iip = p.InsuranceIds)
            {
                int i      = 0;
                int length = p.InsuranceIds.Length - Vector256 <int> .Count + 1;
                int mask   = 8;

                while (mask == 8 && i < length)
                {
                    mask = (int)Lzcnt.LeadingZeroCount(
                        (uint)Avx2.MoveMask(
                            Vector256.AsByte(
                                Avx2.CompareEqual(
                                    Avx2.LoadVector256(iip + i),
                                    insuranceId
                                    )
                                ).Reverse()
                            )
                        ) >> 2;
                    i += Vector256 <int> .Count;
                }
                i -= Vector256 <int> .Count;

                int initial = i + mask;

                if (initial == p.InsuranceIds.Length)
                {
                    return(Array.Empty <ReadOnlyProposal>());
                }

                mask = 0;
                while (mask == 0 && i < length)
                {
                    mask = (int)Lzcnt.LeadingZeroCount(
                        (uint)Avx2.MoveMask(
                            Vector256.AsByte(
                                Avx2.CompareEqual(
                                    Avx2.LoadVector256(iip + i),
                                    insuranceId
                                    )
                                )
                            )
                        ) >> 2;
                    i += Vector256 <int> .Count;
                }
                return(p.Proposals.AsSpan(initial, i - mask - initial).ToArray());
            }
        }
コード例 #4
0
        // removed, not testing loop speed
        //[Benchmark]
        public unsafe ReadOnlyProposal[] PositionalSortedVectorized()
        {
            ProposalResult[] proposals = ProposalBuilder.GetPositionalSortedVectorizedInsurances();
            ProposalResult   p         = proposals[SearchedInsuranceId];

            var minPremium = Vector256.Create(decimal.ToOACurrency(SearchedNetPremium));

            fixed(long *npp = p.NetPremiums)
            {
                int i       = 0;
                int initial = 0;

                for (; i < p.NetPremiums.Length - Vector256 <long> .Count + 1; i += Vector256 <long> .Count)
                {
                    int mask = (int)Lzcnt.LeadingZeroCount(
                        (uint)Avx2.MoveMask(
                            Vector256.AsByte(
                                Avx2.CompareGreaterThan(
                                    Avx2.LoadVector256(npp + i),
                                    minPremium
                                    )
                                ).Reverse()
                            )
                        ) >> 3;

                    if (mask != 8)
                    {
                        initial = i + mask;
                        break;
                    }
                }
                for (; i < p.NetPremiums.Length - Vector256 <long> .Count + 1; i += Vector256 <long> .Count)
                {
                    int mask = (int)Lzcnt.LeadingZeroCount(
                        (uint)Avx2.MoveMask(
                            Vector256.AsByte(
                                Avx2.CompareGreaterThan(
                                    Avx2.LoadVector256(npp + i),
                                    minPremium
                                    )
                                )
                            )
                        ) >> 3;
                    if (mask != 0)
                    {
                        int length = i + Vector256 <long> .Count - mask - initial;
                        return(p.Proposals.AsSpan(initial, length).ToArray());
                    }
                }
                return(p.Proposals.AsSpan(initial).ToArray());
            }
        }
コード例 #5
0
        public List <Proposal> Foreach()
        {
            List <Proposal> result = new List <Proposal>();

            foreach (Proposal p in ProposalBuilder.GetInsurances())
            {
                if (p.InsuranceId == SearchedInsuranceId && p.NetPremium > SearchedNetPremium)
                {
                    result.Add(p);
                }
            }
            return(result);
        }
コード例 #6
0
        public List <Proposal> Foreach()
        {
            List <Proposal> proposals = ProposalBuilder.GetInsurances();
            List <Proposal> result    = new List <Proposal>();

            foreach (Proposal p in proposals)
            {
                if (p.InsuranceId == SearchedInsuranceId)
                {
                    result.Add(p);
                }
            }
            return(result);
        }
コード例 #7
0
        public List <Proposal> For()
        {
            List <Proposal> proposals = ProposalBuilder.GetInsurances();
            List <Proposal> result    = new List <Proposal>(64); // cheating

            for (int i = 0; i < proposals.Count; i++)
            {
                Proposal p = proposals[i];
                if (p.InsuranceId == SearchedInsuranceId && p.NetPremium > SearchedNetPremium)
                {
                    result.Add(p);
                }
            }
            return(result);
        }
コード例 #8
0
        public List <ReadOnlyProposal> ForeachSorted()
        {
            List <ReadOnlyProposal> proposals = ProposalBuilder.GetSortedInsurances();
            List <ReadOnlyProposal> result    = new List <ReadOnlyProposal>(64); // cheating

            foreach (ReadOnlyProposal p in proposals)
            {
                if (p.InsuranceId == SearchedInsuranceId)
                {
                    result.Add(p);
                }
                else if (p.InsuranceId > SearchedInsuranceId)
                {
                    break;
                }
            }
            return(result);
        }
コード例 #9
0
        public List <Proposal> UnrolledFor()
        {
            List <Proposal> proposals = ProposalBuilder.GetInsurances();
            List <Proposal> result    = new List <Proposal>(64); // cheating
            int             i         = 0;

            for (; i <= proposals.Count - 4; i += 4)
            {
                Proposal p0 = proposals[i];
                Proposal p1 = proposals[i + 1];
                Proposal p2 = proposals[i + 2];
                Proposal p3 = proposals[i + 3];
                if (p0.InsuranceId == SearchedInsuranceId)
                {
                    result.Add(p0);
                }
                if (p1.InsuranceId == SearchedInsuranceId)
                {
                    result.Add(p1);
                }
                if (p2.InsuranceId == SearchedInsuranceId)
                {
                    result.Add(p2);
                }
                if (p3.InsuranceId == SearchedInsuranceId)
                {
                    result.Add(p3);
                }
            }
            for (; i < proposals.Count; i++)
            {
                Proposal p = proposals[i];
                if (p.InsuranceId == SearchedInsuranceId)
                {
                    result.Add(p);
                }
            }

            return(result);
        }
コード例 #10
0
        // removed, not testing loop speed
        //[Benchmark]
        public List <ReadOnlyProposal> KeyedSorted()
        {
            Dictionary <int, ImmutableArray <ReadOnlyProposal> > proposalsByKey = ProposalBuilder.GetKeyedSortedInsurances();
            List <ReadOnlyProposal> result = new List <ReadOnlyProposal>();

            var proposals = proposalsByKey[SearchedInsuranceId];

            for (int i = 0; i < proposals.Length; i++)
            {
                ReadOnlyProposal p = proposals[i];
                if (p.NetPremium > SearchedNetPremium)
                {
                    result.Add(p);
                }
                else
                {
                    break;
                }
            }

            return(result);
        }
コード例 #11
0
        public List <ReadOnlyProposal> ForSorted()
        {
            List <ReadOnlyProposal> proposals = ProposalBuilder.GetSortedInsurances();
            List <ReadOnlyProposal> result    = new List <ReadOnlyProposal>(64); // cheating

            for (int i = 0; i < proposals.Count; i++)
            {
                ReadOnlyProposal p = proposals[i];
                if (p.InsuranceId == SearchedInsuranceId)
                {
                    if (p.NetPremium > SearchedNetPremium)
                    {
                        result.Add(p);
                    }
                }
                else if (p.InsuranceId > SearchedInsuranceId)
                {
                    break;
                }
            }
            return(result);
        }
コード例 #12
0
        //[Benchmark]
        public List <ReadOnlyProposal> PositionalSorted()
        {
            ImmutableArray <ReadOnlyProposal>[] proposalsByPosition = ProposalBuilder.GetPositionalSortedInsurances();
            List <ReadOnlyProposal>             result = new List <ReadOnlyProposal>();

            var proposals = proposalsByPosition[SearchedInsuranceId];

            for (int i = 0; i < proposals.Length; i++)
            {
                ReadOnlyProposal p = proposals[i];
                if (p.NetPremium > SearchedNetPremium)
                {
                    result.Add(p);
                }
                else
                {
                    break;
                }
            }

            return(result);
        }
コード例 #13
0
        //[Benchmark]
        public ImmutableArray <ReadOnlyProposal> Positional()
        {
            ImmutableArray <ReadOnlyProposal>[] proposals = ProposalBuilder.GetPositionalSortedInsurances();

            return(proposals[1]);
        }
コード例 #14
0
        // removed, not testing loop speed
        //[Benchmark]
        public ImmutableArray <ReadOnlyProposal> Keyed()
        {
            Dictionary <int, ImmutableArray <ReadOnlyProposal> > proposals = ProposalBuilder.GetKeyedSortedInsurances();

            return(proposals[1]);
        }