Skip to content

Commit 0973e93

Browse files
committed
Added performance chart
1 parent 67b1337 commit 0973e93

File tree

5 files changed

+15
-4
lines changed

5 files changed

+15
-4
lines changed

Package.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ let package = Package(
2020
targets: [
2121
.target(
2222
name: "CRC32C",
23-
dependencies: ["CIntelCRC"]),
23+
dependencies: ["CIntelCRC"],
24+
swiftSettings: [
25+
.define("USE_HARDWARE")
26+
]),
2427
.target(name: "CIntelCRC",
2528
dependencies: [],
2629
cSettings: [

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ crc.finalize()
2020
crc.value
2121
```
2222

23+
## Performance
24+
25+
When using an Intel CPU with a SSE 4.2 instruction set, the specialized `CRC` instruction is used. On other CPUs the calculation falls back to a generic software implemenation.
26+
27+
With SSE 4.2 you can expect a speedup of about 5x.
28+
29+
Below is a chart with the average runtime to calcluate the CRC32-C of a 1GB file on an 8th Gen "Coffee Lake" Intel Core i9 with 2.9 GHz.
30+
31+
![performance graph](performance.png)
2332

2433
## License
2534

Sources/CIntelCRC/include/CIntelCRC.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
#include <stdlib.h>
22
#include <stdint.h>
3-
unsigned int intel_crc(unsigned int c, const unsigned char* data, size_t length);
4-
uint32_t crc32c_append_hw(uint32_t crc, const uint8_t * buf, size_t len);
3+
uint32_t intel_crc(uint32_t crc, const uint8_t * buf, size_t len);

Sources/CRC32C/CRC32C.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public struct CRC32C {
3232

3333
mutating private func crc32IntelSSE42(_ data: [UInt8]) {
3434
value = data.withUnsafeBytes { (ptr) in
35-
crc32c_append_hw(value, ptr.bindMemory(to: UInt8.self).baseAddress, data.count)
35+
intel_crc(value, ptr.bindMemory(to: UInt8.self).baseAddress, data.count)
3636
}
3737
}
3838

performance.png

43 KB
Loading

0 commit comments

Comments
 (0)