Skip to content

Commit 5e3e9b1

Browse files
committed
Lesson 84
1 parent 3894a60 commit 5e3e9b1

File tree

4 files changed

+93
-1
lines changed

4 files changed

+93
-1
lines changed

Benchmark/Benchmark.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<ItemGroup>
1313
<ProjectReference Include="..\BenchmarkLesson\BenchmarkLesson.csproj" />
1414
<ProjectReference Include="..\Lesson81\Lesson81.csproj" />
15+
<ProjectReference Include="..\Lessons\Lessons.csproj" />
1516
</ItemGroup>
1617

1718
</Project>

Benchmark/Lesson84Lists.cs

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
}

Benchmark/Lesson84Swaps.cs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
}

Lessons/Lessons.cs

+19-1
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,24 @@ public void Add(T value)
905905
_array = newArray;
906906
}
907907
}
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+
}
908926
/// <summary>
909927
/// C# УРОКИ | C# ОТ НОВИЧКА К ПРОФЕССИОНАЛУ
910928
/// By #SimpleCode (https://www.youtube.com/c/SimpleCodeIT/featured)
@@ -3365,7 +3383,7 @@ public static void Task83_2()
33653383
}
33663384
}
33673385
/**
3368-
*
3386+
* Обобщения (generics)
33693387
*/
33703388
public static void Task84()
33713389
{

0 commit comments

Comments
 (0)