1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

mosqlのオーバヘッド

Posted at

mosql

いわゆるひとつのクエリビルダ
https://github.com/moskytw/mosql

mosql使う用途くらいだったら特に気にすることもないんだろうけど、確かめてみた。

測定コード

import slowfast

title = "mosql vs format"
one = "insert('tech', {'id': 1, 'name': 'Hoge'})"
two = """'INSERT INTO "tech" ("id", "name") VALUES ("{}", "{}")'.format(1, 'Hoge')"""
setup = "from mosql.query import insert"
slowfast.compare(title, one, two, setup)

title = "mosql vs mosql(escape)"
one = "insert('tech', {'id': 1, 'name': 'Hoge'})"
two = "escape(insert('tech', {'id': 1, 'name': 'Hoge'}))"
setup = "from mosql.query import insert;from mosql.mysql import escape"
slowfast.compare(title, one, two, setup)

結果

$ python example.py
===== mosql vs format =====
(slow) 0.659736[sec]
  insert('tech', {'id': 1, 'name': 'Hoge'})
(fast) 0.008752[sec]
  'INSERT INTO "tech" ("id", "name") VALUES ("{}", "{}")'.format(1, 'Hoge')
75.38 times faster

===== mosql vs mosql(escape) =====
(slow) 0.805398[sec]
  escape(insert('tech', {'id': 1, 'name': 'Hoge'}))
(fast) 0.674377[sec]
  insert('tech', {'id': 1, 'name': 'Hoge'})
1.19 times faster
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?