BitmapOperationsTests.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. using NUnit.Framework;
  2. using System.Diagnostics;
  3. using System.Windows.Media.Imaging;
  4. namespace PixiEditorTests.PerformanceTests
  5. {
  6. [TestFixture]
  7. public class BitmapOperationsTests
  8. {
  9. [TestCase(16,16, 100)]
  10. [TestCase(128, 128, 200)]
  11. [TestCase(512, 512, 300)]
  12. [TestCase(1024, 1024, 500)]
  13. [TestCase(2046, 2046, 1500)]
  14. [TestCase(4096, 4096, 5000)]
  15. public void FillBitmapWithPixelsTest(int width, int height, float maxExecutionTime)
  16. {
  17. WriteableBitmap bitmap = BitmapFactory.New(width, height);
  18. bitmap.Lock();
  19. Stopwatch timer = new Stopwatch(); //Timer starts here, because we don't want to include creating new bitmap in "benchmark"
  20. timer.Start();
  21. for (int i = 0; i < width * height; i++)
  22. {
  23. bitmap.SetPixeli(i, 0xFFFFF);
  24. }
  25. bitmap.Unlock();
  26. timer.Stop();
  27. System.Console.WriteLine("Execution time: " + timer.ElapsedMilliseconds + "ms");
  28. Assert.IsTrue(timer.ElapsedMilliseconds <= maxExecutionTime);
  29. }
  30. }
  31. }