TimeManyDocs.cs
  1. //
  2. // This code is part of Document Solutions for Word demos.
  3. // Copyright (c) MESCIUS inc. All rights reserved.
  4. //
  5. using System;
  6. using System.IO;
  7. using System.Drawing;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using GrapeCity.Documents.Word;
  11.  
  12. namespace DsWordWeb.Demos
  13. {
  14. // This sample creates a 100 instances of GcWordDocument
  15. // and prints the time that it took.
  16. public class TimeManyDocs
  17. {
  18. public GcWordDocument CreateDocx()
  19. {
  20. const int N = 100;
  21.  
  22. // The document to show the resulting time:
  23. GcWordDocument doc = new GcWordDocument();
  24. // Starting time:
  25. var start = Util.TimeNow();
  26. for (int i = 0; i < N; ++i)
  27. new GcWordDocument();
  28. // Delta:
  29. var delta = Util.TimeNow() - start;
  30. // Print out the result:
  31. var message = $"Time used to create {N} instances of GcWordDocument: {delta}.";
  32. doc.Body.Sections.First.GetRange().Paragraphs.Add(message);
  33. // Done:
  34. return doc;
  35. }
  36. }
  37. }
  38.