// Run test private static void Test(string filename, IClouds cloud, int n, int k, Type type, int chunkSize) { StreamWriter sw = new StreamWriter(filename, true); List <TimeSpan> timesUpload = new List <TimeSpan>(); List <TimeSpan> timesDownload = new List <TimeSpan>(); sw.WriteLine("{0} - {1} files each of size {2} {3} chunk size: {4}", cloud.GetName(), n, k, type, chunkSize); sw.Flush(); Console.WriteLine("{0} - {1} files each of size {2} {3}, chunk size: {4}", cloud.GetName(), n, k, type, chunkSize); for (var i = 0; i < 4; i++) { GenerateLoad(n, k, type); List <Stream> streams = GetStreams(n); DeleteLoad(n); cloud.DeleteFiles().Wait(); DateTime t1 = DateTime.Now; for (var j = 0; j < n; j++) { cloud.UploadFile(streams[j], $"{j}.jpg", chunkSize).Wait(); } TimeSpan t = DateTime.Now - t1; timesUpload.Add(t); sw.WriteLine("t{0}(upload): {1} s", i + 1, t.TotalSeconds); sw.Flush(); Console.WriteLine("t{0}(upload): {1} s", i + 1, t.TotalSeconds); t1 = DateTime.Now; cloud.DownloadFiles().Wait(); t = DateTime.Now - t1; timesDownload.Add(t); sw.WriteLine("t{0}(download): {1} s", i + 1, t.TotalSeconds); sw.Flush(); Console.WriteLine("t{0}(download): {1} s\n", i + 1, t.TotalSeconds); } timesUpload.RemoveAt(0); timesDownload.RemoveAt(0); double avgUpload = timesUpload.Count > 0 ? timesUpload.Average(ts => ts.TotalSeconds) : 0.0; double avgDownload = timesDownload.Count > 0 ? timesDownload.Average(ts => ts.TotalSeconds) : 0.0; sw.WriteLine("avg t(upload): {0} s", avgUpload); sw.WriteLine("avg t(download): {0} s", avgDownload); sw.WriteLine(""); sw.Flush(); sw.Close(); Console.WriteLine("avg t(upload): {0} s", avgUpload); Console.WriteLine("avg t(download): {0} s\n", avgDownload); }
private static void Upload(string filename, IClouds cloud, int n, int k, Type type, int chunkSize) { StreamWriter sw = new StreamWriter(filename, true); var files = GenerateLoadRandomNames(n, k, type); List <Stream> streams = GetStreamsFromNames(files); DeleteLoadFromNames(files); cloud.DeleteFiles().Wait(); DateTime t1 = DateTime.Now; foreach (var file in files) { cloud.UploadFile(streams[0], $"{file}.jpg", chunkSize).Wait(); } TimeSpan t = DateTime.Now - t1; sw.WriteLine("{0}\t{1}", t.TotalSeconds, DateTime.Now); sw.Flush(); sw.Close(); }