Created
December 30, 2014 08:53
-
-
Save shibayan/d92e5dcede7d4c96ec93 to your computer and use it in GitHub Desktop.
ストレージのパフォーマンスを簡単に調べるやつ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Diagnostics; | |
using System.IO; | |
using System.Linq; | |
namespace StorageBenchmark | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
if (args.Length != 2) | |
{ | |
return; | |
} | |
var count = int.Parse(args[0]); | |
var size = int.Parse(args[1]); | |
_dummyText = string.Join("", Enumerable.Repeat("0", size)); | |
// テンポラリを作成 | |
var directory = Path.Combine(Environment.CurrentDirectory, "Temp"); | |
Directory.CreateDirectory(directory); | |
// Write | |
Test(WriteFile, count, directory); | |
// Read | |
Test(ReadFile, count, directory); | |
// Delete | |
Test(DeleteFile, count, directory); | |
Directory.Delete(directory, true); | |
} | |
private static string _dummyText; | |
private static void WriteFile(int i, string directory) | |
{ | |
File.WriteAllText(Path.Combine(directory, "temp_" + i + ".tmp"), _dummyText); | |
} | |
private static void ReadFile(int i, string directory) | |
{ | |
File.ReadAllText(Path.Combine(directory, "temp_" + i + ".tmp")); | |
} | |
private static void DeleteFile(int i, string directory) | |
{ | |
File.Delete(Path.Combine(directory, "temp_" + i + ".tmp")); | |
} | |
private static void Test(Action<int, string> func, int count, string directory) | |
{ | |
var sw = new Stopwatch(); | |
sw.Start(); | |
for (int i = 0; i < count; i++) | |
{ | |
func(i, directory); | |
} | |
sw.Stop(); | |
Console.WriteLine("{0} : {1}ms", func.Method.Name, sw.ElapsedMilliseconds); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment