-
-
Notifications
You must be signed in to change notification settings - Fork 959
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Our scenario seems to lack framework possibilities - or can't find documentation (sorry then) #1894
Comments
Something like this? This is only doing the compression/decompression on a single file, but you already said you have multiple files working, so this should handle the other parts. Codepublic class Benchmark
{
[Params(/* compression modes here */)]
public CompressionMode compressionMode;
[Params(/* compression types here */)]
public CompressionType compressionType;
[ParamsSource(nameof(GetCompressionSettings))]
public CompressionSettings compressionSettings;
public IEnumerable<CompressionSettings> GetCompressionSettings()
{
yield return ...;
yield return ...;
}
private const string folderPath = "C:/path/to/files/";
private const string originalFilePath = folderPath + "/originalFileName";
private string filePath;
private byte[] bytes;
[GlobalSetup]
public void GlobalSetup()
{
filePath = folderPath + $"/{compressionType}-{compressionMode}-{compressionSettings}.{extension}";
}
[IterationSetup(Target = nameof(Compress))]
public void CompressSetup()
{
bytes = File.ReadAllBytes(originalFilePath);
}
[Benchmark]
public void Compress()
{
// Do Compress work
bytes = CompressBytes(bytes);
}
[IterationCleanup(Target = nameof(Compress))]
public void CompressCleanup()
{
File.WriteAllBytes(filePath, bytes);
}
[IterationSetup(Target = nameof(Decompress))]
public void DecompressSetup()
{
bytes = File.ReadAllBytes(filePath);
}
[Benchmark]
public void Decompress()
{
// Do Decompress work
bytes = DecompressBytes(bytes);
}
[IterationCleanup(Target = nameof(Decompress))]
public void DecompressCleanup()
{
// Anything to do here? I think we're done.
}
} Unfortunately, there is no way to add custom data to the results table like you're looking for for compression ratio. There is an open issue about it #784. |
Hi Tim, thank you for your really quick and helpful reply! I stumbled across [IterationSetup] - but kept on reading due to the following info:
This kept me from taking it into consideration since a single compress-benchmark iteration takes (dependent on filesize and CompressionType) from 5ms (2kB) - 50ms (10kB) to complete - and therefore doesn't really match the above criteria. Do you think it is nevertheless appropriate to use it? Are there any known alternatives or workarounds for so called "microbenchmarks"? Anyway: Thank you for focussing me on this approach again ... maybe I should give it a try despite the known limitations! |
It is unfortunately necessary to use for this type of benchmark. BDN considers anything under 100ms to be a "microbenchmark", so you can use |
You don't need IterationSetup/Cleanup if you want to include reading/writing the file from/to the filesystem as part of the benchmark. |
That's a great point using the OperationsPerInvoke-option! Being new to BDN it's somewhat hard to connect all the info and possibilities in a way to get a suitable approach for a more complex scenario. Your code and reply helps me a lot! Thank you very much for helping out! I am now curious and keen on my results after benchmark-recreation!
I actually try to keep the compressed data in memory (benchmark-class) in order to apply the corresponding decompression. Let's see... :-) |
Another option with that in mind is using |
I guess this won't work for my scenario since the compression result (byte[]-data) varies on each iteration due to different compression settings. Therefore decompression benchmark might also vary - depending on the data's compression settings. A global approach might lead to a "unified" decompression benchmark since the compressed (global) data has been created only once using a specific (single) compression level setting.... or did I miss something? |
|
Dear BenchmarkDotNet-Team, contributers and friends,
we would like to measure the overall (de-)compression performance on various data with different compression settings.
Therefore our goal is to:
What I’ve managed to do so far:
What I’ve NOT managed to achieve so far:
Question:
Is there any chance to achieve my „wishlist“ using the (extenedable) mechanisms of the framework? If so: Where can I find documentation to achieve my goals or is there any? Unfortunately I couldn’d find any documentation regarding my „unmanaged goals“.
Any help or reply is greatly appreciated. Thank you in advance!
Best regards, Daniel
The text was updated successfully, but these errors were encountered: