github.com/prashanth-hegde/jpath@v0.0.0-20220415185946-76b4f34d3f2e/jpath_test.go (about)

     1  package main
     2  
     3  import (
     4  	"github.com/prashanth-hegde/jpath/common"
     5  	"github.com/prashanth-hegde/jpath/input"
     6  	"github.com/prashanth-hegde/jpath/parser"
     7  	"testing"
     8  )
     9  
    10  // Benchmark_Jpath benchmarking function - generates a flame graph of usage
    11  // To use, put a large file in /tmp/output.json (or whatever filename)
    12  // and then update a complex query in the test below
    13  // Then run this command
    14  // go test -bench=Jpath -cpuprofile=cpuprof_jpath.out
    15  // To render the flame graph, upload cpuprof_jpath.out on this page https://www.speedscope.app/
    16  // refer: https://sathishvj.medium.com/flamegraphs-for-code-optimization-with-golang-and-speedscope-80c20725fdd2
    17  func Benchmark_Jpath(b *testing.B) {
    18  	jsonb, _ := input.ParseInputJson("/tmp/output.json")
    19  	json, _ := common.Tokenize(jsonb)
    20  	_, _ = parser.ProcessExpression(".event_context.container[location_id=3857].changed_values", json)
    21  }