This repository was archived by the owner on Aug 5, 2020. It is now read-only.
forked from hig-dev/libvideo
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
91 lines (75 loc) · 2.56 KB
/
Copy pathProgram.cs
File metadata and controls
91 lines (75 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using VideoLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YoutubeExtractor;
namespace Speed.Test
{
class Program
{
const string Uri = "https://www.youtube.com/watch?v=NLddPakLF1I";
static void Main(string[] args)
{
int times = args.Length == 0 ? 3 : int.Parse(args[0]);
int iterations = args.Length <= 1 ? 2 : int.Parse(args[1]);
Console.WriteLine("Starting...");
Console.WriteLine($"Times: {times}.");
Console.WriteLine($"Iterations: {iterations}.");
Console.WriteLine("Getting results for YoutubeExtractor...");
var elapsed = TimeSpan.Zero;
for (int i = 0; i < times; i++)
{
RunChecked(() =>
{
var watch = Stopwatch.StartNew();
for (int j = 0; j < iterations; j++)
GC.KeepAlive(DownloadUrlResolver.GetDownloadUrls(Uri));
watch.Stop();
elapsed += watch.Elapsed;
});
}
Console.WriteLine($"YoutubeExtractor: took {elapsed}.");
Console.WriteLine("Getting results for libvideo...");
elapsed = TimeSpan.Zero;
using (var service = Client.For(YouTube.Default))
{
for (int i = 0; i < times; i++)
{
RunChecked(() =>
{
var watch = Stopwatch.StartNew();
for (int j = 0; j < iterations; j++)
GC.KeepAlive(service.GetAllVideos(Uri));
watch.Stop();
elapsed += watch.Elapsed;
});
}
}
Console.WriteLine($"libvideo: took {elapsed}.");
}
static void RunChecked(Action action)
{
try
{
action();
}
catch (Exception e)
{
string[] lines =
{
$"A {e.GetType()} was thrown!",
"Message:",
string.Empty,
e.ToString(),
string.Empty,
"Restarting..."
};
Console.WriteLine(string.Join(Environment.NewLine, lines));
RunChecked(action);
}
}
}
}