Created
March 19, 2015 09:13
-
-
Save hbrunn/9362775fea147ed5709f to your computer and use it in GitHub Desktop.
Test odoo performance for select distinct
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
if [ -z "$1" ]; then | |
echo i need to know which test to run | |
exit 1 | |
fi | |
TEST_TYPE=$1 | |
TESTDB=select_distinct_perf | |
PASS_COUNT=20 | |
test_in_branch() | |
{ | |
TYPE=$1 | |
BRANCH=$2 | |
git checkout -q $BRANCH | |
createdb $TESTDB | |
case $TYPE in | |
tests|tests_all) | |
if [ $TYPE = "tests_all" ]; then | |
ALL=base,$(ls ./addons | grep --invert-match hw_escpos | tr '\n' ',') | |
elif [ $TYPE = "tests" ]; then | |
ALL=base | |
else | |
>&2 echo unknown test $TYPE | |
exit 1 | |
fi | |
./openerp-server --database=$TESTDB --stop-after-init --log-handler=:CRITICAL --init=$ALL | |
BEFORE=$(cat /proc/uptime | cut -f1 -d' ') | |
./openerp-server --database=$TESTDB --stop-after-init --log-handler=:CRITICAL --test-enable --update=$ALL | |
AFTER=$(cat /proc/uptime | cut -f1 -d' ') | |
echo "scale=2; $AFTER - $BEFORE" | bc | |
;; | |
select) | |
./openerp-server --database=$TESTDB --stop-after-init --init=base,mail --log-handler=:CRITICAL | |
./odoo.py shell --log-handler=:CRITICAL -d $TESTDB <<HEREDOC | |
import time | |
partners = [] | |
for i in range(1000): | |
partner = self.env['res.partner'].create({ | |
'name': str(i), | |
}) | |
partners.append(partner) | |
for j in range(20): | |
self.env['mail.message'].create({ | |
'model': 'res.partner', | |
'res_id': partner.id, | |
'body': 'test%s' % j, | |
'notification_ids': [ | |
(0, 0, {'partner_id': p.id}) | |
for p in partners | |
] | |
}) | |
partners = partners[-10:] | |
start = time.time() | |
for i in range(10): | |
self.env['mail.message'].search([ | |
('notification_ids.partner_id.create_date', '<', openerp.fields.Datetime.now()), | |
]) | |
self.env['res.partner'].search([ | |
('create_date', '<', openerp.fields.Datetime.now()), | |
]) | |
print '%.2f' % (time.time() - start) | |
HEREDOC | |
;; | |
*) | |
>&2 echo unknown test $TYPE | |
exit 1 | |
;; | |
esac | |
dropdb $TESTDB | |
} | |
SUM1=0 | |
SUM2=0 | |
COUNT=0 | |
while [ $COUNT -lt $PASS_COUNT ]; do | |
TIME_MASTER=$(test_in_branch $TEST_TYPE master) | |
TIME_DISTINCT=$(test_in_branch $TEST_TYPE master-select_distinct) | |
TIME_DISTINCT_NECESSARY=$(test_in_branch $TEST_TYPE master-select_distinct_if_necessary) | |
PERCENTAGE1=$(echo "scale=2; $TIME_DISTINCT/$TIME_MASTER * 100" | bc) | |
PERCENTAGE2=$(echo "scale=2; $TIME_DISTINCT_NECESSARY/$TIME_MASTER * 100" | bc) | |
SUM1=$(echo "scale=2; $SUM1 + $PERCENTAGE1" | bc) | |
SUM2=$(echo "scale=2; $SUM2 + $PERCENTAGE2" | bc) | |
echo master: ${TIME_MASTER}sec master-select_distinct: ${TIME_DISTINCT}sec \(${PERCENTAGE1}%\) master-select_distinct_if_necessary: ${TIME_DISTINCT_NECESSARY}sec \(${PERCENTAGE2}%\) | |
COUNT=$(($COUNT + 1)) | |
done | |
echo average master-select_distinct: $(echo "scale=2; $SUM1 / $COUNT" | bc)% | |
echo average master-select_distinct_if_necessary: $(echo "scale=2; $SUM2 / $COUNT" | bc)% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment