...

Source file src/go.mongodb.org/mongo-driver/benchmark/harness.go

Documentation: go.mongodb.org/mongo-driver/benchmark

     1  // Copyright (C) MongoDB, Inc. 2017-present.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License"); you may
     4  // not use this file except in compliance with the License. You may obtain
     5  // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
     6  
     7  package benchmark // import "go.mongodb.org/mongo-driver/benchmark"
     8  
     9  import (
    10  	"context"
    11  	"testing"
    12  	"time"
    13  
    14  	"go.mongodb.org/mongo-driver/internal/require"
    15  )
    16  
    17  const (
    18  	five            = 5
    19  	ten             = 2 * five
    20  	hundred         = ten * ten
    21  	thousand        = ten * hundred
    22  	tenThousand     = ten * thousand
    23  	hundredThousand = hundred * thousand
    24  	million         = hundred * hundredThousand
    25  
    26  	ExecutionTimeout = five * time.Minute
    27  	StandardRuntime  = time.Minute
    28  	MinimumRuntime   = five * time.Second
    29  	MinIterations    = hundred
    30  )
    31  
    32  type BenchCase func(context.Context, TimerManager, int) error
    33  type BenchFunction func(*testing.B)
    34  
    35  func WrapCase(bench BenchCase) BenchFunction {
    36  	name := getName(bench)
    37  	return func(b *testing.B) {
    38  		ctx := context.Background()
    39  		b.ResetTimer()
    40  		b.ReportAllocs()
    41  		err := bench(ctx, b, b.N)
    42  		require.NoError(b, err, "case='%s'", name)
    43  	}
    44  }
    45  
    46  func getAllCases() []*CaseDefinition {
    47  	return []*CaseDefinition{
    48  		{
    49  			Bench:   BSONFlatDocumentEncoding,
    50  			Count:   tenThousand,
    51  			Size:    75310000,
    52  			Runtime: StandardRuntime,
    53  		},
    54  		{
    55  			Bench:   BSONFlatDocumentDecodingLazy,
    56  			Count:   tenThousand,
    57  			Size:    75310000,
    58  			Runtime: StandardRuntime,
    59  		},
    60  		{
    61  			Bench:   BSONFlatDocumentDecoding,
    62  			Count:   tenThousand,
    63  			Size:    75310000,
    64  			Runtime: StandardRuntime,
    65  		},
    66  		{
    67  			Bench:   BSONDeepDocumentEncoding,
    68  			Count:   tenThousand,
    69  			Size:    19640000,
    70  			Runtime: StandardRuntime,
    71  		},
    72  		{
    73  			Bench:   BSONDeepDocumentDecodingLazy,
    74  			Count:   tenThousand,
    75  			Size:    19640000,
    76  			Runtime: StandardRuntime,
    77  		},
    78  		{
    79  			Bench:   BSONDeepDocumentDecoding,
    80  			Count:   tenThousand,
    81  			Size:    19640000,
    82  			Runtime: StandardRuntime,
    83  		},
    84  		// {
    85  		//	Bench:   BSONFullDocumentEncoding,
    86  		//	Count:   tenThousand,
    87  		//	Size:    57340000,
    88  		//	Runtime: StandardRuntime,
    89  		// },
    90  		// {
    91  		//	Bench:   BSONFullDocumentDecodingLazy,
    92  		//	Count:   tenThousand,
    93  		//	Size:    57340000,
    94  		//	Runtime: StandardRuntime,
    95  		// },
    96  		// {
    97  		//	Bench:   BSONFullDocumentDecoding,
    98  		//	Count:   tenThousand,
    99  		//	Size:    57340000,
   100  		//	Runtime: StandardRuntime,
   101  		// },
   102  		// {
   103  		//	Bench:   BSONFullReaderDecoding,
   104  		//	Count:   tenThousand,
   105  		//	Size:    57340000,
   106  		//	Runtime: StandardRuntime,
   107  		// },
   108  		{
   109  			Bench:   BSONFlatMapDecoding,
   110  			Count:   tenThousand,
   111  			Size:    75310000,
   112  			Runtime: StandardRuntime,
   113  		},
   114  		{
   115  			Bench:   BSONFlatMapEncoding,
   116  			Count:   tenThousand,
   117  			Size:    75310000,
   118  			Runtime: StandardRuntime,
   119  		},
   120  		{
   121  			Bench:   BSONDeepMapDecoding,
   122  			Count:   tenThousand,
   123  			Size:    19640000,
   124  			Runtime: StandardRuntime,
   125  		},
   126  		{
   127  			Bench:   BSONDeepMapEncoding,
   128  			Count:   tenThousand,
   129  			Size:    19640000,
   130  			Runtime: StandardRuntime,
   131  		},
   132  		// {
   133  		//	Bench:   BSONFullMapDecoding,
   134  		//	Count:   tenThousand,
   135  		//	Size:    57340000,
   136  		//	Runtime: StandardRuntime,
   137  		// },
   138  		// {
   139  		//	Bench:   BSONFullMapEncoding,
   140  		//	Count:   tenThousand,
   141  		//	Size:    57340000,
   142  		//	Runtime: StandardRuntime,
   143  		// },
   144  		{
   145  			Bench:   BSONFlatStructDecoding,
   146  			Count:   tenThousand,
   147  			Size:    75310000,
   148  			Runtime: StandardRuntime,
   149  		},
   150  		{
   151  			Bench:   BSONFlatStructTagsDecoding,
   152  			Count:   tenThousand,
   153  			Size:    75310000,
   154  			Runtime: StandardRuntime,
   155  		},
   156  		{
   157  			Bench:   BSONFlatStructEncoding,
   158  			Count:   tenThousand,
   159  			Size:    75310000,
   160  			Runtime: StandardRuntime,
   161  		},
   162  		{
   163  			Bench:   BSONFlatStructTagsEncoding,
   164  			Count:   tenThousand,
   165  			Size:    75310000,
   166  			Runtime: StandardRuntime,
   167  		},
   168  		{
   169  			Bench:   SingleRunCommand,
   170  			Count:   tenThousand,
   171  			Size:    160000,
   172  			Runtime: StandardRuntime,
   173  		},
   174  		{
   175  			Bench:   SingleFindOneByID,
   176  			Count:   tenThousand,
   177  			Size:    16220000,
   178  			Runtime: StandardRuntime,
   179  		},
   180  		{
   181  			Bench:   SingleInsertSmallDocument,
   182  			Count:   tenThousand,
   183  			Size:    2750000,
   184  			Runtime: StandardRuntime,
   185  		},
   186  		{
   187  			Bench:   SingleInsertLargeDocument,
   188  			Count:   ten,
   189  			Size:    27310890,
   190  			Runtime: StandardRuntime,
   191  		},
   192  		{
   193  			Bench:   MultiFindMany,
   194  			Count:   tenThousand,
   195  			Size:    16220000,
   196  			Runtime: StandardRuntime,
   197  		},
   198  		{
   199  			Bench:   MultiInsertSmallDocument,
   200  			Count:   tenThousand,
   201  			Size:    2750000,
   202  			Runtime: StandardRuntime,
   203  		},
   204  		{
   205  			Bench:              MultiInsertLargeDocument,
   206  			Count:              ten,
   207  			Size:               27310890,
   208  			Runtime:            StandardRuntime,
   209  			RequiredIterations: tenThousand,
   210  		},
   211  	}
   212  }
   213  

View as plain text