#!/usr/bin/env bash

echo 'Performance: setup'
rm -f ./taskchampion.sqlite3
if [[ -e ./data/taskchampion.sqlite3 ]]
then
  echo '  - Using existing data.'
  cp data/* .
else
  echo '  - Loading data. This step will take several minutes.'
  ./load
  mkdir -p data
  cp taskchampion.sqlite3 perf.rc data
fi

# Allow override.
if [[ -z $TASK ]]
then
  TASK=${CMAKE_BINARY_DIR}/src/task
fi

# Run benchmarks.
# Note that commands are run twice - warm cache testing.

echo 'Performance: benchmarks'

echo '  - task next...'
$TASK rc.debug:1 rc:perf.rc next >/dev/null 2>&1
$TASK rc.debug:1 rc:perf.rc next 2>&1 | grep "Perf task"

echo '  - task list...'
$TASK rc.debug:1 rc:perf.rc list >/dev/null 2>&1
$TASK rc.debug:1 rc:perf.rc list 2>&1 | grep "Perf task"

echo '  - task all...'
$TASK rc.debug:1 rc:perf.rc all >/dev/null 2>&1
$TASK rc.debug:1 rc:perf.rc all 2>&1 | grep "Perf task"

echo '  - task add...'
$TASK rc.debug:1 rc:perf.rc add >/dev/null 2>&1
$TASK rc.debug:1 rc:perf.rc add This is a task with an average sized description length project:P priority:H +tag1 +tag2 2>&1 | grep "Perf task"

echo '  - task export...'
$TASK rc.debug:1 rc:perf.rc export >/dev/null 2>&1
$TASK rc.debug:1 rc:perf.rc export 2>&1 >export.json | grep "Perf task"

echo '  - task import...'
rm -f ./taskchampion.sqlite3
$TASK rc.debug:1 rc:perf.rc import ${CMAKE_SOURCE_DIR}/performance/export.json 2>&1 | grep "Perf task"

echo 'End'
exit 0
