Skip to content

Commit

Permalink
Benchmarks: X86 disassembler and rewriter.
Browse files Browse the repository at this point in the history
  • Loading branch information
uxmal committed Nov 28, 2024
1 parent 7c75226 commit 74e05ba
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 6 deletions.
48 changes: 48 additions & 0 deletions src/Benchmarks/Arch/X86/X86DisassemblerBenchmarks.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Diagnosers;
using Reko.Arch.X86;
using Reko.Core;
using Reko.Core.Memory;
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Reko.Benchmarks.Arch.X86
{
[Config(typeof(Config))]
public class X86DisassemblerBenchmarks
{
private readonly ByteMemoryArea machineCode;
private readonly X86ArchitectureFlat32 arch;

public X86DisassemblerBenchmarks()
{
var mem = new byte[4096];
var rnd = new Random(0x142621A2);
rnd.NextBytes(mem);
this.machineCode = new ByteMemoryArea(Address.Ptr32(0x10000), mem);
this.arch = new X86ArchitectureFlat32(new ServiceContainer(), "x86-protected-32", new());
}

[Benchmark]
public void DisassembleBytes()
{
var rdr = arch.CreateImageReader(machineCode, 0);
var dasm = arch.CreateDisassembler(rdr);
foreach (var instr in dasm)
;
}

public class Config : ManualConfig
{
public Config()
{
AddDiagnoser(MemoryDiagnoser.Default);
}
}
}
}
51 changes: 51 additions & 0 deletions src/Benchmarks/Arch/X86/X86RewriterBenchmarks.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using BenchmarkDotNet.Attributes;
using Reko.Arch.X86;
using Reko.Core.Memory;
using Reko.Core;
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Diagnosers;
using System.Reflection;

namespace Reko.Benchmarks.Arch.X86
{
[Config(typeof(Config))]
public class X86RewriterBenchmarks
{
private readonly ByteMemoryArea machineCode;
private readonly X86ArchitectureFlat32 arch;

public X86RewriterBenchmarks()
{
var mem = new byte[4096];
var rnd = new Random(0x142621A2);
rnd.NextBytes(mem);
this.machineCode = new ByteMemoryArea(Address.Ptr32(0x10000), mem);
this.arch = new X86ArchitectureFlat32(new ServiceContainer(), "x86-protected-32", new());
}

[Benchmark]
public void LiftMachineCode()
{
var rdr = arch.CreateImageReader(machineCode, 0);
var rw = arch.CreateRewriter(rdr, arch.CreateProcessorState(), new StorageBinder(), new NullRewriterHost());
foreach (var rtlc in rw)
;
}

public class Config : ManualConfig
{
public Config()
{
AddDiagnoser(MemoryDiagnoser.Default);
}
}


}
}
9 changes: 3 additions & 6 deletions subjects/regression.log

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 74e05ba

Please sign in to comment.