LoginSignup
2
0

More than 1 year has passed since last update.

testQLとqの比較

Posted at

始めに

csvファイルに対して、SQLでデータ検索できる便利ツールのtextQLqを比較する機会がありました
その結果をシェアします

検証方法

  1. pythonでsubprocessでコマンド実行
  2. CSVファイルは2種類。1つは350行, 20カラム, 73k。もう1つは800行, 22カラム, 220k(いずれも約)
  3. pythonファイルは同じものを使い、SQLはほぼ同一でfrom等の実行コマンドに依存する部分のみ異なります。実行コマンドのパラメータはヘッダーの指定のみです
  4. シンプルなSQLで名称を条件にIDを取得するだけのものです
  5. textQLのバージョン 2.0.3、qのバージョン 3.1.6

結果

textQLの方が3倍近い速度でした

cProfileの結果(1部)を貼り付けておきます(ファイル名、関数名はリネームしています)
単純に1つ1つの実行結果が遅いみたいですね

なお、python scriptとしては、実行結果をプログラム内でキャッシュすることで改善を計ります

textQL-cumtime.sh
ncalls  tottime  percall  cumtime  percall filename:lineno(function)
    211/1    0.000    0.000   33.080   33.080 {built-in method builtins.exec}
        1    0.057    0.057   33.080   33.080 test_python.py:1(<module>)
     2737    0.066    0.000   32.205    0.012 test_python.py:227(exec_cmd)
     2737    0.228    0.000   32.134    0.012 subprocess.py:461(run)
     2737    0.022    0.000   28.798    0.011 subprocess.py:1110(communicate)
     2737    0.169    0.000   28.772    0.011 subprocess.py:1952(_communicate)
     4593    0.050    0.000   28.047    0.006 selectors.py:403(select)
     4593   27.989    0.006   27.989    0.006 {method 'poll' of 'select.poll' objects}
      346    0.110    0.000   21.739    0.063 test_python.py:350(get_test1)
     1678    0.004    0.000   21.730    0.013 test_python.py:245(get_test2)
     1059    0.015    0.000   10.514    0.010 test_python.py:250(get_test3)
q-cumtime.sh
ncalls  tottime  percall  cumtime  percall filename:lineno(function)
    211/1    0.000    0.000  103.530  103.530 {built-in method builtins.exec}
        1    0.047    0.047  103.530  103.530 test_python.py:1(<module>)
     2737    0.051    0.000  102.596    0.037 test_python.py:206(exec_cmd)
     2737    0.282    0.000  102.540    0.037 subprocess.py:461(run)
     2737    0.020    0.000   99.083    0.036 subprocess.py:1110(communicate)
     2737    0.217    0.000   99.060    0.036 subprocess.py:1952(_communicate)
     5474    0.057    0.000   98.407    0.018 selectors.py:403(select)
     5474   98.339    0.018   98.339    0.018 {method 'poll' of 'select.poll' objects}
      346    0.118    0.000   69.666    0.201 test_python.py:329(get_test1)
     1678    0.030    0.000   65.547    0.039 test_python.py:224(get_test2)
     1059    0.033    0.000   37.139    0.035 test_python.py:229(get_test3)

終わりに

バージョンを確認する時に気づいたのですが、qはpythonで動いているようですね
それなら当然の結果となります
(textQLはgolang)

q --version.sh
q version 3.1.6
Python: 3.9.15 (main, Nov  6 2022, 11:31:59) // [Clang 14.0.3 ]
Copyright (C) 2012-2021 Harel Ben-Attia (harelba@gmail.com, @harelba on twitter)
http://harelba.github.io/q/
2
0
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
2
0