Skip to main content

Benchmarks

These benchmarks compare Hangfire 1.8.25, from NuGet, with NightShift. Both ran in the same process with the same settings and the same SQL client (Microsoft.Data.SqlClient), each against its own database.

For the differences in features, see NightShift compared with Hangfire.

End to end on SQL Server​

Empty jobs on SQL Server 2022 and .NET 10, with 20 workers. Each number is the median of 3 rounds. Higher is better.

Jobs per secondHangfireNightShiftNightShift with AllowDelayedDurability
Enqueue in a loop, one caller174218332
Enqueue from 64 callers at once1,5233,1793,063
EnqueueManyNo free equivalent4,1163,738
Processing562 to 648606 to 794974 to 1,000

The database ran in a Docker container, where a round trip takes about 0.7 ms and a commit about 2 ms, so the absolute numbers are low for both libraries. Results vary by 10% to 20% between runs; the processing row gives the range seen in two runs.

In-process operations​

These measure the library alone, with no database. Lower is better.

Operation (.NET 10)HangfireNightShiftDifference
Call the job method17.0 ns3.5 ns79% less time
Serialize a job with an object argument2.38 µs, 10.97 KB1.59 µs, 1.84 KB33% less time, 83% less memory
Deserialize that job3.34 µs, 17.32 KB3.04 µs, 2.08 KB9% less time, 88% less memory
Create a job from a lambda0.70 µs, 2.08 KB0.74 µs, 2.08 KBAbout the same
Run a sync job through all filters0.58 µs, 1.62 KB0.27 µs, 0.63 KB53% less time, 61% less memory
Run an async job through all filters1.82 µs, 1.69 KB1.47 µs, 0.70 KB19% less time, 58% less memory
Operation (.NET 8)HangfireNightShiftDifference
Call the job method16.6 ns4.2 ns75% less time
Serialize a job with an object argument2.60 µs, 10.95 KB1.84 µs, 1.84 KB29% less time, 83% less memory
Deserialize that job3.61 µs, 17.30 KB3.07 µs, 2.08 KB15% less time, 88% less memory
Create a job from a lambda0.89 µs, 2.20 KB0.89 µs, 2.20 KBAbout the same
Run a sync job through all filters0.55 µs, 1.70 KB0.37 µs, 0.75 KB33% less time, 56% less memory
Run an async job through all filters1.96 µs, 1.77 KB1.63 µs, 0.82 KB17% less time, 54% less memory

What the numbers mean​

  • A loop of Enqueue calls is about 1.25 times faster, and about twice as fast with AllowDelayedDurability. NightShift sends a commit as one round trip, so creating a job takes two round trips where Hangfire takes four. A caller still waits for the database to store each job before it gets the job's ID, which is why a loop can't be many times faster.
  • Many callers at once are about twice as fast. Up to 8 callers write at the same time; the callers beyond them are written in groups, one round trip and one commit per group.
  • Creating many jobs at once is over 20 times faster. EnqueueMany writes a group of jobs in a few round trips, where a loop pays several per job.
  • Processing is about the same by default, and about 1.7 times faster with AllowDelayedDurability. With the option, fetching a job and moving it to Processing don't wait for the disk, and only the commit of the final state does.
  • AllowDelayedDurability is a trade-off you choose. A job's creation and its final state are always stored before the call returns. If SQL Server stops in the few milliseconds after a job was fetched, the job runs again. See SQL Server options.
  • NightShift's clearest gain is memory. Serializing and deserializing a job allocates 83% to 88% less, because it uses System.Text.Json, and running a job allocates over 50% less. That means less garbage collection on busy servers.
  • The source generator speeds up the call, not the whole job. The call itself is about 4 times faster, but that saves about 13 ns in a job run that takes 0.7 to 2 µs before any database work. A generated call and NightShift's compiled fallback are close to each other, and both are faster than reflection.
  • The generator's other gain is the first call of each method. NightShift's fallback compiles a delegate on first use, which took 138 µs to 173 µs, against about 0.5 µs for a generated invoker. It happens once per method, and Hangfire has no such step, because it uses reflection.
  • A full job run is faster and lighter. Running a job through its filters takes 17% to 53% less time and allocates 54% to 61% less memory, because NightShift keeps each job method's filter list instead of building and sorting it on every run. The saving is a fraction of a microsecond, so it shows in memory use more than in throughput.

How they were measured​

Date2026-11-09 for the in-process tables; the two "run a job" rows and the end-to-end table on 2026-11-10
HardwareIntel Core Ultra 7 255H, 16 cores, Windows 11
DatabaseSQL Server 2022 Developer (16.0.4295) in a Docker container on the same machine
ToolsBenchmarkDotNet 0.15.8, and a timed end-to-end run
Runtimes.NET 8.0 and .NET 10.0

The in-process benchmarks use an empty job and a storage connection that does nothing, so they show library overhead alone. Results on other hardware will differ, so run them against your own database before relying on them. Use a full SQL Server: LocalDB is the Express engine and hides what a server does under load.

Run them yourself​

The code is in benchmarks/Masterly.NightShift.Benchmarks. It isn't part of the solution. To run it:

cd benchmarks/Masterly.NightShift.Benchmarks
dotnet run -c Release -f net10.0 -- --filter '*' # all BenchmarkDotNet benchmarks, on .NET 8 and .NET 10
dotnet run -c Release -f net10.0 -- throughput 3000 4 20 # end to end: jobs, rounds, workers
dotnet run -c Release -f net10.0 -- throughput 6000 4 20 64 # the same, enqueueing from 64 callers at once

Set NightShift_SqlServer_ConnectionStringTemplate to a connection string with a {0} placeholder for the database name. The end-to-end run creates the databases NightShiftBench_Hangfire and NightShiftBench_NightShift; NS_DD=1 turns on AllowDelayedDurability for NightShift.

See also​