Skip to content

Conversation

@qjustfeelitp
Copy link

@qjustfeelitp qjustfeelitp commented Oct 1, 2022

experiments resulted in
image

latest net6 and ef6 used
that async enumerable pass through is just for fun
for the best perf without proper indices, the best way to go is at least I think separate queries see the last commit, maybe raw SQL with parameters and separate queries will be fastest, give it a shot

BenchmarkDotNet=v0.13.2, OS=Windows 11 (10.0.22000.856/21H2)
12th Gen Intel Core i9-12900, 1 CPU, 24 logical and 16 physical cores
.NET SDK=7.0.100-rc.1.22431.12
  [Host] : .NET 6.0.9 (6.0.922.41905), X64 RyuJIT AVX2

Job=InProcess  Toolchain=InProcessEmitToolchain  
Method Mean Error StdDev Median Ratio Allocated Alloc Ratio
GetAuthors 531,522,260.00 ns 10,165,518.398 ns 15,215,269.291 ns 530,266,350.00 ns 1.000 192848136 B 1.000
GetAuthors_Optimized 3,905,332.13 ns 222,979.085 ns 657,458.862 ns 3,654,059.77 ns 0.007 13656 B 0.000
GetAuthors_OptimizedInline 3,585,813.95 ns 134,630.094 ns 377,517.218 ns 3,410,118.75 ns 0.007 57883 B 0.000
GetAuthors_OptimizedInlineWithParameters 3,389,941.35 ns 67,457.295 ns 82,843.616 ns 3,372,915.62 ns 0.006 60217 B 0.000
GetAuthors_OptimizedWithoutExpressions 3,197,558.28 ns 62,037.349 ns 86,967.699 ns 3,199,947.66 ns 0.006 13652 B 0.000
GetAuthors_OptimizedAsync 4,108,718.76 ns 99,986.187 ns 294,811.528 ns 4,133,792.97 ns 0.008 17296 B 0.000
GetAuthors_OptimizedAsyncPassThrough 10.29 ns 0.145 ns 0.135 ns 10.27 ns 0.000 176 B 0.000
GetAuthors_OptimizedParameterized 3,294,977.28 ns 66,837.663 ns 185,206.851 ns 3,226,722.66 ns 0.006 15412 B 0.000
GetAuthors_OptimizedRecordSpan 3,249,605.65 ns 61,928.241 ns 135,933.991 ns 3,219,528.91 ns 0.006 13893 B 0.000
GetAuthors_OptimizedRecordList 3,198,880.39 ns 63,606.253 ns 84,912.521 ns 3,184,392.58 ns 0.006 13981 B 0.000
GetAuthors_OptimizedRecordListInline 4,159,730.20 ns 275,687.471 ns 812,870.730 ns 4,022,810.55 ns 0.008 55783 B 0.000
GetAuthors_OptimizedRecordListInlineWithParameters 4,011,464.06 ns 248,033.087 ns 731,331.154 ns 3,656,656.45 ns 0.008 58651 B 0.000
GetAuthors_OptimizedRecordListWithoutExpressions 3,903,027.41 ns 248,330.099 ns 732,206.900 ns 3,756,379.30 ns 0.007 13986 B 0.000
GetAuthors_OptimizedRecordAsync 4,638,188.51 ns 92,168.553 ns 129,207.439 ns 4,625,794.53 ns 0.009 17274 B 0.000
GetAuthors_OptimizedRecordAsyncPassThrough 10.53 ns 0.080 ns 0.071 ns 10.53 ns 0.000 176 B 0.000
GetAuthors_OptimizedRecordListParameterized 3,986,353.55 ns 232,241.476 ns 684,769.233 ns 3,841,485.55 ns 0.007 15746 B 0.000
GetAuthors_RawSqlArray 3,140,509.43 ns 59,518.686 ns 70,852.761 ns 3,112,501.17 ns 0.006 14118 B 0.000
GetAuthors_RawSqlWithoutParametersArray 4,127,885.30 ns 255,149.075 ns 752,312.804 ns 3,959,378.12 ns 0.008 12173 B 0.000
GetAuthors_OptimizedMultipleQueries 3,494,956.88 ns 67,157.316 ns 65,957.464 ns 3,494,540.23 ns 0.007 90322 B 0.000
GetAuthors_MultipleQuery 2,540,432.96 ns 46,510.594 ns 45,679.622 ns 2,534,841.41 ns 0.005 26285 B 0.000
GetAuthors_MultipleQueryWithoutSelectorExpressions 2,562,001.44 ns 50,546.824 ns 56,182.661 ns 2,569,712.50 ns 0.005 26285 B 0.000

i think that without apropriate indices, the perf way to go is with separate queries
@m-jovanovic
Copy link

m-jovanovic commented Oct 4, 2022

@qjustfeelitp Are you sure GetAuthors_OptimizedAsyncPassThrough and GetAuthors_OptimizedRecordAsyncPassThrough are executing correctly? It seems like the method completes without enumerating the IAsyncEnumerable and you get such fast times.

@qjustfeelitp
Copy link
Author

as i mentioned in description they are there just for fun, they are not meant to be taken seriously 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants