diff --git a/semantic-tags/bench/Main.hs b/semantic-tags/bench/Main.hs new file mode 100644 index 000000000..eb4f1d20d --- /dev/null +++ b/semantic-tags/bench/Main.hs @@ -0,0 +1,33 @@ +module Main (main) where + +import Tags.Tagging.Precise +import qualified Data.ByteString as B +import Gauge +import Source.Loc (Loc (..)) +import Source.Range +import Source.Source as Source +import Source.Span (Pos (..), Span (..)) +import Data.Char (ord) + +main :: IO () +main = do + bytes <- fmap fromUTF8 $ B.readFile "/Users/tclem/github/github/app/models/user.rb" + -- bytes <- fmap fromUTF8 $ B.readFile "/Users/tclem/Downloads/jquery-3.5.1.min.js" + -- let lineIndexes = B.elemIndices (toEnum (ord '\n')) (Source.bytes bytes) + defaultMain + [ baselineCalculateLine bytes + , calculateLinePRVersion bytes + , calculateLineWithMap bytes + ] + +baselineCalculateLine :: Source -> Benchmark +baselineCalculateLine bytes = bench "baseline calculateLineAndSpans" $ do + nf (baselineCalculateLineAndSpans bytes) (Loc (Range 73754 73757) (Span (Pos 1 73669) (Pos 1 73672))) + +calculateLinePRVersion :: Source -> Benchmark +calculateLinePRVersion bytes = bench "calculateLineAndSpansPRVersion " $ do + nf (calculateLineAndSpansPRVersion bytes) (Loc (Range 73754 73757) (Span (Pos 1 73669) (Pos 1 73672))) + +calculateLineWithMap :: Source -> Benchmark +calculateLineWithMap src = bench "calculateLineAndSpansWithIndexes" $ do + nf (calculateLineAndSpans src (LineIndices mempty)) (Loc (Range 73754 73757) (Span (Pos 1 73669) (Pos 1 73672))) diff --git a/semantic-tags/semantic-tags.cabal b/semantic-tags/semantic-tags.cabal index 4ad5f1cbd..a1d8358be 100644 --- a/semantic-tags/semantic-tags.cabal +++ b/semantic-tags/semantic-tags.cabal @@ -48,6 +48,8 @@ library , semantic-source ^>= 0.1.0 , semantic-proto ^>= 0 , text ^>= 1.2.3.1 + , containers + , deepseq hs-source-dirs: src test-suite test @@ -64,3 +66,15 @@ test-suite test , tasty-hedgehog ^>= 1.0.0.1 , tasty-hunit >= 0.10 && <1 , text + +benchmark benchmarks + import: haskell + hs-source-dirs: bench + type: exitcode-stdio-1.0 + main-is: Main.hs + ghc-options: -threaded -static -rtsopts + build-depends: base + , bytestring ^>= 0.10.8.2 + , semantic-tags + , semantic-source + , gauge ^>= 0.2.5