Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Diagnostics;
- public enum TimeFrame {
- Year, TwoYears, Long
- }
- public class Paper {
- public string Name { get; set; }
- public Person Author { get; set; }
- public DateTime PublicationDate { get; set; }
- public Paper(string name, Person author, DateTime publicationDate) {
- Name = name;
- Author = author;
- PublicationDate = publicationDate;
- }
- public Paper() {
- Name = "Paper Name";
- Author = new Person("", "");
- PublicationDate = DateTime.Now;
- }
- public override string ToString() {
- return $"Paper \"{Name}\" by {Author}, published at {PublicationDate:yyyy-MM-dd HH:mm}";
- }
- }
- public class ResearchTeam {
- private string _topic;
- private string _organization;
- private int _registrationNumber;
- private TimeFrame _researchTimeFrame;
- private Paper[] _papers;
- public Paper? LastPaper {
- get {
- return _papers.MaxBy(p => p.PublicationDate);
- }
- }
- public bool this[TimeFrame timeFrame] {
- get {
- return _researchTimeFrame == timeFrame;
- }
- }
- public string Topic {
- get {
- return _topic;
- }
- }
- public string Organization {
- get {
- return _organization;
- }
- }
- public int RegistrationNumber {
- get {
- return _registrationNumber;
- }
- }
- public TimeFrame ResearchTimeFrame {
- get {
- return _researchTimeFrame;
- }
- }
- public Paper[] Papers {
- get {
- return _papers;
- }
- }
- public ResearchTeam(string topic, string organization, int registrationNumber, TimeFrame researchTimeFrame) {
- _topic = topic;
- _organization = organization;
- _registrationNumber = registrationNumber;
- _researchTimeFrame = researchTimeFrame;
- _papers = Array.Empty<Paper>();
- }
- public ResearchTeam() {
- _topic = "Topic";
- _organization = "Organization";
- _registrationNumber = 0;
- _researchTimeFrame = TimeFrame.Year;
- _papers = Array.Empty<Paper>();
- }
- public void AddPapers(params Paper[] papers) {
- _papers = _papers.Concat(papers).ToArray();
- }
- public override string ToString() {
- return $"Research team \"{_topic}\" ({_organization}, {_registrationNumber}), " +
- $"{_researchTimeFrame} time frame, {_papers.Length} papers: " +
- $"{string.Join(", ", _papers.AsEnumerable())}";
- }
- public string ToShortString() {
- return $"Research team \"{_topic}\" ({_organization}, {_registrationNumber}), " +
- $"{_researchTimeFrame} time frame, {_papers.Length} papers";
- }
- }
- public class Person {
- public string FirstName { get; }
- public string LastName { get; }
- public Person(string firstName, string lastName) {
- FirstName = firstName;
- LastName = lastName;
- }
- public override string ToString() { return $"{FirstName} {LastName}"; }
- }
- class Program {
- public static void Main(string[] args) {
- var researchTeam = new ResearchTeam();
- Console.WriteLine("ResearchTeam.ToShortString(): {0}", researchTeam.ToShortString());
- foreach (var enumValue in Enum.GetValues<TimeFrame>()) {
- Console.WriteLine("ResearchTeam[{0}]: {1}", enumValue, researchTeam[enumValue]);
- }
- Console.WriteLine("===============================================================");
- researchTeam = new ResearchTeam("влияние мэшапов на стул по утрам",
- "ООО \"Разработка очка\"", 123, TimeFrame.Year);
- Console.WriteLine("ResearchTeam.ToShortString(): {0}", researchTeam);
- researchTeam.AddPapers(new Paper {
- Name = "напас лавандос вместо лоперамида",
- Author = new Person("хуй", "моржовый"),
- PublicationDate = new DateTime(2022, 5, 9, 12, 0, 0)
- }, new Paper {
- Name = "производство мэшапов из лоперамида",
- Author = new Person("кто", "такой"),
- PublicationDate = new DateTime(2021, 12, 1, 5, 0, 0)
- }, new Paper {
- Name = "мэшапы с меладзе как слабительное",
- Author = new Person("пиздец", "блядский"),
- PublicationDate = new DateTime(2021, 7, 15, 18, 0, 0)
- }, new Paper {
- Name = "мэшапы с новогодним поздравлением от путина: с новым мэшапом, пидоры!",
- Author = new Person("путин", "владимир"),
- PublicationDate = new DateTime(2021, 12, 31, 12, 0, 0)
- });
- Console.WriteLine("ResearchTeam.LastPaper: {0}", researchTeam.LastPaper);
- Console.WriteLine("===============================================================");
- var array1 = new Paper[10000];
- var array2 = new Paper[100][];
- var array3 = new Paper[100][];
- // init array1
- for (var i = 0; i < array1.Length; i++) {
- array1[i] = new Paper {
- Name = "paper" + i,
- Author = new Person("author" + i, "author" + i),
- PublicationDate = new DateTime(2021, 1, 1, 0, 0, 0)
- };
- }
- // init array2
- for (var i = 0; i < array2.Length; i++) {
- var arr = new Paper[100];
- for (var j = 0; j < arr.Length; j++) {
- arr[j] = new Paper {
- Name = "paper" + i + j,
- Author = new Person("author" + i + j, "author" + i + j),
- PublicationDate = new DateTime(2021, 1, 1, 0, 0, 0)
- };
- }
- array2[i] = arr;
- }
- // init array3
- var random = new Random();
- for (var i = 0; i < array3.Length; i++) {
- var arr = new Paper[random.Next(50, 150)];
- for (var j = 0; j < arr.Length; j++) {
- arr[j] = new Paper {
- Name = "paper" + i + j,
- Author = new Person("author" + i + j, "author" + i + j),
- PublicationDate = new DateTime(2021, 1, 1, 0, 0, 0)
- };
- }
- array3[i] = arr;
- }
- // test access to array1
- var sw = new Stopwatch();
- sw.Start();
- for (var i = 0; i < 10000000; i++) {
- var paper = array1[random.Next(0, array1.Length)];
- DoSomething(paper);
- }
- sw.Stop();
- Console.WriteLine("array1|access: {0}ms", sw.ElapsedMilliseconds);
- // test access to array2
- sw.Restart();
- for (var i = 0; i < 10000000; i++) {
- var paper = array2[random.Next(0, array2.Length)][random.Next(0, array2.Length)];
- DoSomething(paper);
- }
- sw.Stop();
- Console.WriteLine("array2|access: {0}ms", sw.ElapsedMilliseconds);
- // test access to array3
- sw.Restart();
- for (var i = 0; i < 10000000; i++) {
- var arr = array3[random.Next(0, array3.Length)];
- var paper = arr[random.Next(0, arr.Length)];
- DoSomething(paper);
- }
- sw.Stop();
- Console.WriteLine("array3|access: {0}ms", sw.ElapsedMilliseconds);
- // test write to array1
- sw.Restart();
- for (var i = 0; i < 10000000; i++) {
- array1[random.Next(0, array1.Length)] = new Paper {
- Name = "paper" + i,
- Author = new Person("author" + i, "author" + i),
- PublicationDate = new DateTime(2021, 1, 1, 0, 0, 0)
- };
- }
- sw.Stop();
- Console.WriteLine("array1|write: {0}ms", sw.ElapsedMilliseconds);
- // test write to array2
- sw.Restart();
- for (var i = 0; i < 10000000; i++) {
- array2[random.Next(0, array2.Length)][random.Next(0, array2.Length)] = new Paper {
- Name = "paper" + i,
- Author = new Person("author" + i, "author" + i),
- PublicationDate = new DateTime(2021, 1, 1, 0, 0, 0)
- };
- }
- sw.Stop();
- Console.WriteLine("array2|write: {0}ms", sw.ElapsedMilliseconds);
- // test write to array3
- sw.Restart();
- for (var i = 0; i < 10000000; i++) {
- var arr = array3[random.Next(0, array3.Length)];
- arr[random.Next(0, arr.Length)] = new Paper {
- Name = "paper" + i,
- Author = new Person("author" + i, "author" + i),
- PublicationDate = new DateTime(2021, 1, 1, 0, 0, 0)
- };
- }
- sw.Stop();
- Console.WriteLine("array3|write: {0}ms", sw.ElapsedMilliseconds);
- }
- private static void DoSomething(Paper paper) {
- }
- }
Add Comment
Please, Sign In to add comment