비ꡐ - Count() > 0, Any(), Count > 0

비ꡐ - Count() > 0, Any(), Count > 0

Count() > 0 on a List with 1,000,000 elements

Any() on the same list

Count > 0 using the property

κ²°κ³Ό

| Method         | Mean      | Allocated |
|----------------|-----------|-----------|
| CountMethod    | 20.521 us | 0 B       |
| AnyMethod      | 0.989 us  | 0 B       |
| PropertyAccess | 0.045 us  | 0 B       |

κΈ€ : Boost Your C# Code: Why Any() is Faster Than Count() > 0 for Performance

μ €μž : Sukhpinder Singh

1개의 μ’‹μ•„μš”

Any()κ°€ Count()보닀 νš¨μœ¨μ μ΄κΈ΄ν•œλ° Npgsql.EntityFrameworkCore.PostgreSQLμ—μ„œλŠ” μ§€μ›λ˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.

1개의 μ’‹μ•„μš”

IQueryable.Any() 와 같은 κ°„λ‹¨ν•œ 쿼리가 μ§€μ›λ˜μ§€ μ•Šμ„ 리가 μ—†μ„ν…λ°μš”.

1개의 μ’‹μ•„μš”

Npgsql.EntityFrameworkCore.PostgreSQL 5.x 버전 μ‚¬μš©μ€‘μΈλ° Any()λ₯Ό μ‚¬μš©ν•˜λ©΄ could not be translated라고 였λ₯˜λ‚©λ‹ˆλ‹€. κ·Έλž˜μ„œ μ–΄μ©”μˆ˜ 없이 Count()λ₯Ό μ‚¬μš©ν•˜κ³  μžˆμŠ΅λ‹ˆλ‹€.

1개의 μ’‹μ•„μš”

μ§€κΈˆ 버전이 10인데, λ„ˆλ¬΄ 였래된 버전을 μ‚¬μš©ν•˜κ³  계신 λ“― ν•©λ‹ˆλ‹€.

ν˜„μž¬λŠ” μ•„λ¬΄λŸ° 문제 없이 λ©λ‹ˆλ‹€.

2개의 μ’‹μ•„μš”