Commit c86ba1b0 authored by Kirill Smelkov's avatar Kirill Smelkov

X bench-cpu += crc32, adler32

parent 9562304c
......@@ -893,9 +893,12 @@ bench_cpu() {
\"s|^This machine benchmarks at \([0-9.]\+\) pystones/second$|Benchmark`hostname`/pystone 1 \1 pystone/s|\""
sizev="1024 4096 $((2*1024*1024))"
for size in $sizev; do
nrun tcpu.py sha1 $size
nrun tcpu_go sha1 $size
benchv="adler32 crc32 sha1"
for bench in $benchv; do
for size in $sizev; do
nrun tcpu.py $bench $size
nrun tcpu_go $bench $size
done
done
datav="null-1K null-4K null-2M wczdata prod1-avg prod1-max"
......
......@@ -27,6 +27,9 @@ import (
"crypto/sha1"
"flag"
"fmt"
"hash"
"hash/adler32"
"hash/crc32"
"io/ioutil"
"log"
"os"
......@@ -79,15 +82,14 @@ func benchit(benchname string, bencharg string, benchf func(*testing.B, string))
}
func BenchmarkSha1(b *testing.B, arg string) {
func benchHash(b *testing.B, h hash.Hash, arg string) {
blksize, err := strconv.Atoi(arg)
if err != nil {
b.Fatal(err)
}
data := make([]byte, blksize)
h := sha1.New()
b.ResetTimer()
for i := 0; i < b.N; i++ {
......@@ -95,6 +97,10 @@ func BenchmarkSha1(b *testing.B, arg string) {
}
}
func BenchmarkAdler32(b *testing.B, arg string) { benchHash(b, adler32.New(), arg) }
func BenchmarkCrc32(b *testing.B, arg string) { benchHash(b, crc32.NewIEEE(), arg) }
func BenchmarkSha1(b *testing.B, arg string) { benchHash(b, sha1.New(), arg) }
func xreadfile(t testing.TB, path string) []byte {
data, err := ioutil.ReadFile(path)
if err != nil {
......@@ -118,6 +124,8 @@ func BenchmarkUnzlib(b *testing.B, zfile string) {
var benchv = map[string]func(*testing.B, string) {
"adler32": BenchmarkAdler32,
"crc32": BenchmarkCrc32,
"sha1": BenchmarkSha1,
"unzlib": BenchmarkUnzlib,
}
......
......@@ -24,6 +24,7 @@ from __future__ import print_function
import sys
import hashlib
import zhash
import zlib
from time import time
from math import ceil, log10
......@@ -111,11 +112,10 @@ def benchit(benchf, bencharg, ttarget = 1.):
# ---- 8< ----
def bench_sha1(b, blksize):
def _bench_hasher(b, h, blksize):
blksize = int(blksize)
data = '\0'*blksize
h = hashlib.sha1()
b.reset_timer()
n = b.N
......@@ -125,6 +125,11 @@ def bench_sha1(b, blksize):
i += 1
def bench_adler32(b, blksize): _bench_hasher(b, zhash.Adler32Hasher(), blksize)
def bench_crc32(b, blksize): _bench_hasher(b, zhash.CRC32Hasher(), blksize)
def bench_sha1(b, blksize): _bench_hasher(b, hashlib.sha1(), blksize)
def readfile(path):
with open(path, 'r') as f:
return f.read()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment