LoginSignup
0
2

More than 5 years have passed since last update.

nysol(python) vs pandas pandas より、遅いけどメモリは食わない

Last updated at Posted at 2018-09-15

nysolがそれほど速くなかった事例。

  • 使用データ
    kaggle においてある国連データ
    から、2014年のデータ year_origin_destination_hs96_6_2014.csv をダウンロードしてください。

  • jupyter notebook で、軽く検証してみました。メモリ消費は圧倒的にnysol が少ないです。

#!/usr/bin/env python
# -*- encoding:utf-8 -*-
import pandas as pd
import nysol.mcmd as nm
#
  • pandas
%%time
columns={"year":"int","origin":"str","dest":"str","hs96":"str","export_val":"float","import_val":"float"}
tg = 'year_origin_destination_hs96_6_2014.csv'
df = pd.read_csv(tg,dtype = columns)
df.groupby('origin')[['export_val','import_val']].sum()
  • pandas 結果
CPU times: user 8.98 s, sys: 740 ms, total: 9.72 s
Wall time: 9.72 s
  • nysol
%%time
tg = 'year_origin_destination_hs96_6_2014.csv'
xxx1 = nm.msum({"i":tg,"k":"origin","f":"export_val,import_val"})
xxx1.run()
  • nysol 結果
CPU times: user 14.4 s, sys: 1.66 s, total: 16.1 s
Wall time: 14.2 s

次にもっと重いデータでやってみました。メモリ消費は、圧倒的にnysol が少ないです。

国連の貿易データ全部

  • pandas 結果
CPU times: user 1min 58s, sys: 13.6 s, total: 2min 11s
Wall time: 2min 38s
16G メモリ消費
  • nysol 結果
CPU times: user 3min 52s, sys: 26.6 s, total: 4min 19s
Wall time: 4min 44s
1.6G メモリ消費
0
2
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
0
2