<jupyter_start><jupyter_text>time comparison of calcimp by C and Python Fisrt make a thin sliced taper data to compare calculation time of calcimp by C language and Python.<jupyter_code>def yy(x):
    return (20*x/1000 + 10)
yy(0)
yy(1000)<jupyter_output><empty_output><jupyter_text>Write data for legacy C version of calcimp.<jupyter_code>f = open('taper.men','w')
f.write('% 10 - 30 taper\n')
for i in range(1000):
    f.write('{0},{1},1,\n'.format(yy(i),yy(i+1)))
f.write('30,0,0,\n')
f.close()<jupyter_output><empty_output><jupyter_text>And for new Python version.<jupyter_code>f = open('taper.xmen','w')
f.write('# 10 - 30 taper\n')
f.write('[,\n')
for i in range(1000):
    f.write('{0},{1},1,\n'.format(yy(i),yy(i+1)))
f.write('30,0,0,\n')
f.write('],\n')
f.close()<jupyter_output><empty_output><jupyter_text>Compare calculation time.<jupyter_code>!time ~/develop/kanutils-20180129/calcimp taper.men -o taper-c.imp
%%time 
!python /home/yoshinobu/Py_files/calcimpy/calcimpy.py taper.xmen -o taper-python.imp<jupyter_output>CPU times: user 240 ms, sys: 44 ms, total: 284 ms
Wall time: 6.19 s<jupyter_text>Though using numba, python version is ofcourse slower than C version but not bad.<jupyter_code>!python -m cProfile -s time /home/yoshinobu/Py_files/calcimpy/calcimpy.py taper.xmen<jupyter_output>2697032 function calls (2688231 primitive calls) in 7.427 seconds

   Ordered by: internal time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
   800800    2.979    0.000    5.283    0.000 imped.py:160(calc_impedance)
   800000    1.733    0.000    1.733    0.000 {built-in method impcore.calc_transmission}
      801    0.662    0.001    6.243    0.008 imped.py:174(input_impedance)
   800000    0.571    0.000    0.571    0.000 {built-in method impcore.zo2zi}
      504    0.179    0.000    0.179    0.000 {built-in method marshal.loads}
      800    0.178    0.000    0.178    0.000 xmensur.py:160(end_mensur)
      800    0.120    0.000    0.120    0.000 imped.py:53(radimp)
    98/66    0.096    0.001    0.234    0.004 {built-in method _imp.create_dynamic}
1286/1272    0.065    0.000    0.182    0.000 {built-in method builtins.__build_class__}
    587/1    0.035    0.000    7.428    7.428 {built-in method builtins.exec}
      678    0.031  [...]<jupyter_text>Plot data to check that they are same.<jupyter_code>import pandas as pd
import matplotlib.pyplot as plt
dataC = pd.read_csv('taper-c.imp',header = 0)
dataPy = pd.read_csv('taper-python.imp', header=0)
dd = pd.DataFrame()<jupyter_output><empty_output><jupyter_text>Merge data for plotting.<jupyter_code>dd['x'] = dataC['freq']
dd['C'] = dataC['mag']
dd['Py'] = dataPy['imp.mag']
dd.head()
dd.tail()
dd.plot( x = 'x', y = ['C','Py'])<jupyter_output>/home/yoshinobu/anaconda3/lib/python3.6/site-packages/pandas/plotting/_core.py:1716: UserWarning: Pandas doesn't allow columns to be created via a new attribute name - see https://pandas.pydata.org/pandas-docs/stable/indexing.html#attribute-access
  series.name = label<jupyter_text>Ofcourse output is same. More check with compressed mensur data.<jupyter_code>%%time
!python /home/yoshinobu/Py_files/calcimpy/calcimpy.py taper-a.xmen
dataPy2 = pd.read_csv('taper-a.imp', header=0)
dd['Py2'] = dataPy2['imp.mag']
dd.plot( x = 'x', y = ['C','Py','Py2'])
dd.head()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14873323397913563, 'fraction_numerical': 0.09567809239940388, 'mean_word_length': 3.8427128427128427, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 30, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '332316', 'license': 'MIT', 'n_tokens_mistral': 1510, 'n_tokens_neox': 1321, 'n_words': 284, 'path': 'example/10_time-cmp/time-cmp-python.ipynb', 'repo_name': 'Yoshinobu-Ishizaki/calcimp.jl', 'size': '3355'}