File tree 4 files changed +93
-1
lines changed
4 files changed +93
-1
lines changed Original file line number Diff line number Diff line change 12
12
<ItemGroup >
13
13
<ProjectReference Include =" ..\BenchmarkLesson\BenchmarkLesson.csproj" />
14
14
<ProjectReference Include =" ..\Lesson81\Lesson81.csproj" />
15
+ <ProjectReference Include =" ..\Lessons\Lessons.csproj" />
15
16
</ItemGroup >
16
17
17
18
</Project >
Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Linq ;
4
+ using System . Text ;
5
+ using System . Threading . Tasks ;
6
+ using BenchmarkDotNet . Attributes ;
7
+ using BenchmarkDotNet . Running ;
8
+ using System . Collections ;
9
+
10
+ namespace Benchmark
11
+ {
12
+ [ MemoryDiagnoser ]
13
+ public class ListsBenchmark
14
+ {
15
+ [ Benchmark ]
16
+ public void ArrayListSwapBenchmark ( )
17
+ {
18
+ ArrayList arrayList = new ArrayList ( ) ;
19
+ for ( int i = 0 ; i < 1000 ; i ++ )
20
+ {
21
+ arrayList . Add ( i ) ;
22
+ }
23
+ }
24
+ [ Benchmark ]
25
+ public void ListBenchmark ( )
26
+ {
27
+ List < int > list = new List < int > ( ) ;
28
+ for ( int i = 0 ; i < 1000 ; i ++ )
29
+ {
30
+ list . Add ( i ) ;
31
+ }
32
+ }
33
+ [ Benchmark ]
34
+ public void ObjectListBenchmark ( )
35
+ {
36
+ List < object > list = new List < object > ( ) ;
37
+ for ( int i = 0 ; i < 1000 ; i ++ )
38
+ {
39
+ list . Add ( i ) ;
40
+ }
41
+ }
42
+ }
43
+ }
Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Linq ;
4
+ using System . Text ;
5
+ using System . Threading . Tasks ;
6
+ using BenchmarkDotNet . Attributes ;
7
+ using BenchmarkDotNet . Running ;
8
+ using Lessons ;
9
+
10
+ namespace Benchmark
11
+ {
12
+ [ MemoryDiagnoser ]
13
+ public class SwapsBenchmark
14
+ {
15
+ [ Benchmark ]
16
+ public void GenericSwapBenchmark ( )
17
+ {
18
+ double a = 1 ;
19
+ double b = 5.3 ;
20
+ SwapTestClass . GenericSwap ( ref a , ref b ) ;
21
+ }
22
+ [ Benchmark ]
23
+ public void SwapBenchmark ( )
24
+ {
25
+ object a = 2 ;
26
+ object b = 4 ;
27
+ SwapTestClass . Swap ( ref a , ref b ) ;
28
+ }
29
+ }
30
+ }
Original file line number Diff line number Diff line change @@ -905,6 +905,24 @@ public void Add(T value)
905
905
_array = newArray ;
906
906
}
907
907
}
908
+ /**
909
+ * класс SwapTestClass для Task84()
910
+ */
911
+ public static class SwapTestClass
912
+ {
913
+ public static void GenericSwap < T > ( ref T a , ref T b )
914
+ {
915
+ T temp = a ;
916
+ a = b ;
917
+ b = temp ;
918
+ }
919
+ public static void Swap ( ref object a , ref object b )
920
+ {
921
+ object temp = a ;
922
+ a = b ;
923
+ b = temp ;
924
+ }
925
+ }
908
926
/// <summary>
909
927
/// C# УРОКИ | C# ОТ НОВИЧКА К ПРОФЕССИОНАЛУ
910
928
/// By #SimpleCode (https://www.youtube.com/c/SimpleCodeIT/featured)
@@ -3365,7 +3383,7 @@ public static void Task83_2()
3365
3383
}
3366
3384
}
3367
3385
/**
3368
- *
3386
+ * Обобщения (generics)
3369
3387
*/
3370
3388
public static void Task84 ( )
3371
3389
{
You can’t perform that action at this time.
0 commit comments