Skip to content

Added for b.Loop() in benchmarks functions #710

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions benchmarks/encode_string_test.go
Original file line number Diff line number Diff line change
@@ -2,8 +2,9 @@ package test

import (
"bytes"
"github.com/json-iterator/go"
"testing"

jsoniter "github.com/json-iterator/go"
)

func Benchmark_encode_string_with_SetEscapeHTML(b *testing.B) {
@@ -14,7 +15,7 @@ func Benchmark_encode_string_with_SetEscapeHTML(b *testing.B) {
}
var json = jsoniter.ConfigCompatibleWithStandardLibrary
b.ReportAllocs()
for i := 0; i < b.N; i++ {
for b.Loop() {
buf := &bytes.Buffer{}
enc := json.NewEncoder(buf)
enc.SetEscapeHTML(true)
7 changes: 4 additions & 3 deletions benchmarks/jsoniter_large_file_test.go
Original file line number Diff line number Diff line change
@@ -2,10 +2,11 @@ package test

import (
"encoding/json"
"github.com/json-iterator/go"
"io/ioutil"
"os"
"testing"

jsoniter "github.com/json-iterator/go"
)

//func Test_large_file(t *testing.T) {
@@ -126,7 +127,7 @@ func init() {
*/
func Benchmark_jsoniter_large_file(b *testing.B) {
b.ReportAllocs()
for n := 0; n < b.N; n++ {
for b.Loop() {
file, _ := os.Open("/tmp/large-file.json")
iter := jsoniter.Parse(jsoniter.ConfigDefault, file, 4096)
count := 0
@@ -145,7 +146,7 @@ func Benchmark_jsoniter_large_file(b *testing.B) {

func Benchmark_json_large_file(b *testing.B) {
b.ReportAllocs()
for n := 0; n < b.N; n++ {
for b.Loop() {
file, _ := os.Open("/tmp/large-file.json")
bytes, _ := ioutil.ReadAll(file)
file.Close()
2 changes: 1 addition & 1 deletion benchmarks/stream_test.go
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ import (
func Benchmark_stream_encode_big_object(b *testing.B) {
var buf bytes.Buffer
var stream = jsoniter.NewStream(jsoniter.ConfigDefault, &buf, 100)
for i := 0; i < b.N; i++ {
for b.Loop() {
buf.Reset()
stream.Reset(&buf)
encodeObject(stream)