<commit_before>{-# LANGUAGE FlexibleInstances     #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings     #-}
{-# LANGUAGE TypeSynonymInstances  #-}

-- | Benchmark TPC-H queries executed using DSH against native SQL queries
-- executed using HDBC.
module Main where

import           Control.Monad
import           System.Environment
import           System.Exit

import           Control.DeepSeq          (NFData)
import qualified Criterion                as B
import qualified Criterion.Main           as M
import qualified Database.HDBC            as H
import qualified Database.HDBC.ODBC       as O

import qualified Database.DSH             as Q
import qualified Database.DSH.Backend.Sql as S
import qualified Database.DSH.Compiler    as C

import           Queries.TPCH.NonStandard
import           Queries.TPCH.Standard

-- provide sql text in environment.
-- prepare query on every go.
-- Produce list result with the same type as DSH query.

--------------------------------------------------------------------------------
-- Execute benchmarks

-- | Benchmark the complete execution of a DSH query
benchmarkDSH :: (Q.QA a, NFData a)
             => String
             -> O.Connection
             -> Q.Q a
             -> B.Benchmark
benchmarkDSH benchName c q = B.bench benchName $ B.nfIO (C.runQ (S.sqlBackend c) q)

--------------------------------------------------------------------------------
-- Benchmark definition

benchmarks :: O.Connection -> [B.Benchmark]
benchmarks c =
    [ B.bgroup "tpch"
        [ benchmarkDSH "q1" c q1Default
        , benchmarkDSH "q2" c q2Default
        , benchmarkDSH "q3" c q3Default
        , benchmarkDSH "q4" c q4Default
        , benchmarkDSH "q5" c q5Default
        , benchmarkDSH "q6" c q6Default
        , benchmarkDSH "q7" c q7Default
        , benchmarkDSH "q8" c q8Default
        , benchmarkDSH "q9" c q9Default
        , benchmarkDSH "q10" c q10Default
        , benchmarkDSH "q11" c q11Default
        , benchmarkDSH "q12" c q12Default
        , benchmarkDSH "q13" c q13Default
        , benchmarkDSH "q14" c q14Default
        , benchmarkDSH "q15" c q15Default
        , benchmarkDSH "q16" c q16
        , benchmarkDSH "q17" c q17
        , benchmarkDSH "q18" c q18Default
        -- , benchmarkDSH "q19" c q19Default
        , benchmarkDSH "q20" c q20Default
        -- , benchmarkDSH "q21" c q21Default
        , benchmarkDSH "q22" c q22Default
        ]
    , B.bgroup "nested"
        [ benchmarkDSH "custfromorders" c (custFromOrders "GERMANY")
        , benchmarkDSH "custrevenues" c (custRevenues "GERMANY")
        , benchmarkDSH "expectedrevenuefor" c (expectedRevenueFor "GERMANY")
        , benchmarkDSH "shippingdelay" c shippingDelay
        , benchmarkDSH "shippingdelayinteral" c shippingDelayInterval
        , benchmarkDSH "toporderspercust" c (topOrdersPerCust' 10 "GERMANY")
        , benchmarkDSH "regionstopcustomers" c (regionsTopCustomers "EUROPE" 10)
        , benchmarkDSH "unshippeditemspercustomer" c (unshippedItemsPerCustomer "GERMANY")
        , benchmarkDSH "cheapersuppliersinregion" c (cheaperSuppliersInRegion "EUROPE")
        , benchmarkDSH "cheapersuppliersinregionavg" c (cheaperSuppliersInRegionAvg "EUROPE")<commit_msg>Disable query shippingdelay for benchmarking.<commit_after>{-# LANGUAGE FlexibleInstances     #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings     #-}
{-# LANGUAGE TypeSynonymInstances  #-}

-- | Benchmark TPC-H queries executed using DSH against native SQL queries
-- executed using HDBC.
module Main where

import           Control.Monad
import           System.Environment
import           System.Exit

import           Control.DeepSeq          (NFData)
import qualified Criterion                as B
import qualified Criterion.Main           as M
import qualified Database.HDBC            as H
import qualified Database.HDBC.ODBC       as O

import qualified Database.DSH             as Q
import qualified Database.DSH.Backend.Sql as S
import qualified Database.DSH.Compiler    as C

import           Queries.TPCH.NonStandard
import           Queries.TPCH.Standard

-- provide sql text in environment.
-- prepare query on every go.
-- Produce list result with the same type as DSH query.

--------------------------------------------------------------------------------
-- Execute benchmarks

-- | Benchmark the complete execution of a DSH query
benchmarkDSH :: (Q.QA a, NFData a)
             => String
             -> O.Connection
             -> Q.Q a
             -> B.Benchmark
benchmarkDSH benchName c q = B.bench benchName $ B.nfIO (C.runQ (S.sqlBackend c) q)

--------------------------------------------------------------------------------
-- Benchmark definition

benchmarks :: O.Connection -> [B.Benchmark]
benchmarks c =
    [ B.bgroup "tpch"
        [ benchmarkDSH "q1" c q1Default
        , benchmarkDSH "q2" c q2Default
        , benchmarkDSH "q3" c q3Default
        , benchmarkDSH "q4" c q4Default
        , benchmarkDSH "q5" c q5Default
        , benchmarkDSH "q6" c q6Default
        , benchmarkDSH "q7" c q7Default
        , benchmarkDSH "q8" c q8Default
        , benchmarkDSH "q9" c q9Default
        , benchmarkDSH "q10" c q10Default
        , benchmarkDSH "q11" c q11Default
        , benchmarkDSH "q12" c q12Default
        , benchmarkDSH "q13" c q13Default
        , benchmarkDSH "q14" c q14Default
        , benchmarkDSH "q15" c q15Default
        , benchmarkDSH "q16" c q16
        , benchmarkDSH "q17" c q17
        , benchmarkDSH "q18" c q18Default
        -- , benchmarkDSH "q19" c q19Default
        , benchmarkDSH "q20" c q20Default
        -- , benchmarkDSH "q21" c q21Default
        , benchmarkDSH "q22" c q22Default
        ]
    , B.bgroup "nested"
        [ benchmarkDSH "custfromorders" c (custFromOrders "GERMANY")
        , benchmarkDSH "custrevenues" c (custRevenues "GERMANY")
        , benchmarkDSH "expectedrevenuefor" c (expectedRevenueFor "GERMANY")
        , benchmarkDSH "shippingdelayinterval" c shippingDelayInterval
        , benchmarkDSH "toporderspercust" c (topOrdersPerCust' 10 "GERMANY")
        , benchmarkDSH "regionstopcustomers" c (regionsTopCustomers "EUROPE" 10)
        , benchmarkDSH "unshippeditemspercustomer" c (unshippedItemsPerCustomer "GERMANY")
        , benchmarkDSH "cheapersuppliersinregion" c (cheaperSuppliersInRegion "EUROPE")
        , benchmarkDSH "cheapersuppliersinregionavg" c (cheaperSuppliersInRegionAvg "EUROPE")
{'fraction_non_alphanumeric': 0.12565606668724916, 'fraction_numerical': 0.022846557579499844, 'mean_word_length': 2.143619602134886, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6494144', 'n_tokens_mistral': 2066, 'n_tokens_neox': 1911, 'n_words': 545}