Skip to content

Commit f3b7d7f

Browse files
Merge pull request #530 from SyncfusionExamples/Performance_benchmark_examples
1009767-Creating performance benchmark samples for .NET Word library
2 parents b88ae2e + bae990e commit f3b7d7f

3 files changed

Lines changed: 29 additions & 49 deletions

File tree

Performance-metrices/Clone-and-merge/.NET/Clone-and-merge-word-document/Clone-and-merge-word-document/Clone-and-merge-word-document.csproj

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,15 @@
1111
<ItemGroup>
1212
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
1313
</ItemGroup>
14-
14+
<ItemGroup>
15+
<None Update="Data\SourceDocument\Document-100.docx">
16+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
17+
</None>
18+
<None Update="Data\DestinationDocument\Document-100.docx">
19+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
20+
</None>
21+
<None Update="Output\.gitkeep">
22+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
23+
</None>
24+
</ItemGroup>
1525
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 17 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,30 @@
1-
using System.ComponentModel;
2-
using System.Diagnostics;
1+
using System.Diagnostics;
32
using Syncfusion.DocIO;
43
using Syncfusion.DocIO.DLS;
54

65
class Program
76
{
87
static void Main()
98
{
10-
string sourceFolder = Path.GetFullPath("../../../Data/SourceDocument/");
11-
string destinationFolder = Path.GetFullPath("../../../Data/DestinationDocument/");
12-
string outputFolder = Path.GetFullPath("../../../Output/");
13-
14-
Directory.CreateDirectory(outputFolder);
15-
16-
// Get all source files
17-
string[] sourceFiles = Directory.GetFiles(sourceFolder, "*.docx");
18-
19-
foreach (string sourcePath in sourceFiles)
9+
using (FileStream sourceFileStream = new FileStream(Path.GetFullPath(@"Data/SourceDocument/Document-100.docx"), FileMode.Open, FileAccess.Read))
2010
{
21-
string fileName = Path.GetFileName(sourcePath);
22-
string destinationPath = Path.Combine(destinationFolder, fileName);
23-
24-
if (!File.Exists(destinationPath))
25-
{
26-
Console.WriteLine($"Skipping {fileName} - No matching destination file found.");
27-
continue;
28-
}
29-
30-
string outputPath = Path.Combine(outputFolder, fileName);
31-
32-
Stopwatch stopwatch = Stopwatch.StartNew();
33-
34-
try
11+
using (FileStream destinationFileStream = new FileStream(Path.GetFullPath(@"Data/DestinationDocument/Document-100.docx"), FileMode.Open, FileAccess.Read))
3512
{
36-
// Open source and destination document
37-
WordDocument sourceDocument = new WordDocument(sourcePath);
38-
WordDocument destinationDocument = new WordDocument(destinationPath);
39-
40-
// Clone and merge all slides
41-
foreach (WSection section in sourceDocument.Sections)
13+
using (WordDocument mainDoc = new WordDocument(sourceFileStream, FormatType.Docx))
4214
{
43-
WSection clonedSection = section.Clone();
44-
destinationDocument.Sections.Add(clonedSection);
45-
}
46-
47-
// Save the merged document.
48-
destinationDocument.Save(outputPath);
49-
50-
stopwatch.Stop();
51-
Console.WriteLine($"{fileName} is cloned and merged in {stopwatch.Elapsed.TotalSeconds} seconds.");
52-
sourceDocument.Close();
53-
destinationDocument.Close();
54-
}
55-
catch (Exception ex)
56-
{
57-
Console.WriteLine($"Error processing {fileName}: {ex.Message}");
15+
using (WordDocument mergeDoc = new WordDocument(destinationFileStream, FormatType.Docx))
16+
{
17+
Stopwatch sw = Stopwatch.StartNew();
18+
mainDoc.ImportContent(mergeDoc, ImportOptions.UseDestinationStyles);
19+
sw.Stop();
20+
Console.WriteLine("Time taken for Merge Documents:" + sw.Elapsed.TotalSeconds);
21+
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/MergedDocument.docx"), FileMode.Create))
22+
{
23+
mainDoc.Save(outputFileStream, FormatType.Docx);
24+
}
25+
}
26+
}
5827
}
5928
}
6029
}
61-
}
30+
}

0 commit comments

Comments
 (0)