IoPoc.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading;
  8. using System.Threading.Tasks;
  9. using Xunit;
  10. namespace Bsm.Core.Tests
  11. {
  12. public class IoPoc
  13. {
  14. [Fact]
  15. public void CalcFileSizeA()
  16. {
  17. var dir = @"Y:\BeatSaverAll";
  18. long jsonSize = 0;
  19. var sw = new Stopwatch();
  20. sw.Restart();
  21. IoUtil.LookupFilesRecursively(dir, (p, f) =>
  22. {
  23. var ext = Path.GetExtension(p.cFileName)?.ToLower();
  24. if (ext != ".jpg" && ext!=".png") return;
  25. jsonSize += p.FileSize;
  26. });
  27. sw.Stop();//35s
  28. var kb = jsonSize / 1024f;
  29. var mb = kb / 1024f;
  30. var gb = mb / 1024f;
  31. }
  32. [Fact]
  33. public void CalcFileSizeB()
  34. {
  35. var dir = @"Z:\BeatSaverAll";
  36. var sw = new Stopwatch();
  37. sw.Restart();
  38. var jsonSize = Directory.GetFiles(dir, "*.dat", SearchOption.AllDirectories).Select(p => IoUtil.GetFileSize(p)).Sum();
  39. sw.Stop(); //2m0s
  40. var kb = jsonSize / 1024f;
  41. var mb = kb / 1024f;
  42. var gb = mb / 1024f;
  43. }
  44. }
  45. }