Commit c86ba1b0 authored by Kirill Smelkov's avatar Kirill Smelkov

X bench-cpu += crc32, adler32

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