-
Notifications
You must be signed in to change notification settings - Fork 32
-
Performance Concerns: Sqids significantly slower than HashIds in benchmarksHello Sqids team, I recently conducted a performance benchmark comparing Sqids with HashIds (ullmark/hashids.net), and I wanted to share my findings with you. While I appreciate the new features and improvements Sqids brings over HashIds, I've noticed a significant performance difference that I believe is worth discussing. Benchmark ResultsHere are the results of my benchmark test:
Observations
These benchmarks were conducted using both Questions and Concerns
I appreciate the work you've done on Sqids and I'm looking forward to hearing your thoughts on these performance issues. If you need any additional information or if you'd like me to run more specific benchmarks, please let me know. |
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 3 comments
-
Hey @Pouria7, thanks for your efforts. Could you please share the actual benchmark code?
Beta Was this translation helpful? Give feedback.
All reactions
-
[MemoryDiagnoser(false)]
public class IdGeneratorBenchmark
{
private int id = 5732;
[Benchmark(Baseline = true)]
public string HashId()
{
Hashids hashids = new Hashids();
string encodedId = hashids.Encode(id);
var decodedId = hashids.DecodeSingle(encodedId);
//var decodedIds = hashids.Decode(result);
return encodedId + decodedId.ToString();
}
[Benchmark]
public string Sqids()
{
var sqd = new SqidsEncoder<int>();
string encodedId = sqd.Encode(id);
var decodedIds = sqd.Decode(encodedId);
return encodedId + decodedIds[0].ToString();
}
}
Beta Was this translation helpful? Give feedback.
All reactions
-
I realized that the initial benchmarks might have been affected by the time taken to create instances of the encoders. To address this, I modified the setup to create instances only once: [GlobalSetup] public void Setup() { hashids = new Hashids(); sqids = new SqidsEncoder<int>(); } Updated Benchmark ResultsAfter making these changes, here are the new benchmark results:
|
Beta Was this translation helpful? Give feedback.