Share SHA-256 SIMD impl
Signed-off-by: Hidde Beydals <hello@hidde.co>
This commit is contained in:
		
							parent
							
								
									51c030e43c
								
							
						
					
					
						commit
						c4c6362d87
					
				|  | @ -0,0 +1,27 @@ | |||
| package sha256simd | ||||
| 
 | ||||
| import ( | ||||
| 	"github.com/minio/sha256-simd" | ||||
| 	"github.com/opencontainers/go-digest" | ||||
| 	"hash" | ||||
| ) | ||||
| 
 | ||||
| const SHA256SIMD = digest.Algorithm("sha256simd") | ||||
| 
 | ||||
| func init() { | ||||
| 	digest.RegisterAlgorithm(SHA256SIMD, &sha256simdhash{}) | ||||
| } | ||||
| 
 | ||||
| type sha256simdhash struct{} | ||||
| 
 | ||||
| func (sha256simdhash) Available() bool { | ||||
| 	return true | ||||
| } | ||||
| 
 | ||||
| func (sha256simdhash) Size() int { | ||||
| 	return sha256.Size | ||||
| } | ||||
| 
 | ||||
| func (sha256simdhash) New() hash.Hash { | ||||
| 	return sha256.New() | ||||
| } | ||||
|  | @ -18,6 +18,7 @@ package digest | |||
| 
 | ||||
| import ( | ||||
| 	"crypto/rand" | ||||
| 	"github.com/fluxcd/source-controller/internal/digest/sha256simd" | ||||
| 	"testing" | ||||
| 
 | ||||
| 	. "github.com/onsi/gomega" | ||||
|  | @ -100,12 +101,16 @@ func benchmarkMultiDigesterWrite(b *testing.B, algos []digest.Algorithm, pSize i | |||
| } | ||||
| 
 | ||||
| func BenchmarkMultiDigester_Write(b *testing.B) { | ||||
| 	const pSize = 1024 * 2 | ||||
| 	const pSize = 1024 * 10 | ||||
| 
 | ||||
| 	b.Run("sha256", func(b *testing.B) { | ||||
| 		benchmarkMultiDigesterWrite(b, []digest.Algorithm{digest.SHA256}, pSize) | ||||
| 	}) | ||||
| 
 | ||||
| 	b.Run("sha256-simd", func(b *testing.B) { | ||||
| 		benchmarkMultiDigesterWrite(b, []digest.Algorithm{sha256simd.SHA256SIMD}, pSize) | ||||
| 	}) | ||||
| 
 | ||||
| 	b.Run("blake3", func(b *testing.B) { | ||||
| 		benchmarkMultiDigesterWrite(b, []digest.Algorithm{digest.BLAKE3}, pSize) | ||||
| 	}) | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue