아아 한동안은 Iron Python 릴리스 특집을 계속 쓸 것 같은.. 흐흐
Iron Python을 이제 받아서 대충 한번 둘러 봤습니다. 프로젝트 자체는 Visual Studio .NET 기반의 프로젝트 파일로 되어있고, mono에서 컴파일이 가능한 프로젝트 파일은 따로 없는 듯 합니다. 그렇지만 다행히도 컴파일된 바이너리가 들어있어서 빌드 걱정 없이 그냥 실행해 볼 수 있었습니다.
% mono bin/IronPythonConsole.exe
>>> [x*2 for x in range(10)]
[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
>>> import sys
>>> sys.platform
'java-clr'
>>> raise ValueError
IronPython.Objects.PythonValueError:
in <0x000df> IronPython.Objects.Ops:Raise (object,object,object)
in <0x00047> input_3:Run (IronPython.Objects.Frame)
in <0x001c5> IronPythonConsole.IronPython:DoInteractive ()
트레이스 백 모양이 파이썬 트레이스백이 아니라 자바 형식이라 좀 어색하군요 흐흐; 그리고 sys.platform이 웬 ‘java-clr’ –;; 아직 os모듈은 없고, 현재 Iron Python에 들어있는 모듈은 __builtins__, imp, math, nt, re, struct, sys, time이 있습니다. 뭔가 벤치마크를 위해 time을 빼놓지는 않았다는 느낌이.. :
CPython보다 빠르다는 속도를 한번 시험해 봤습니다. 테스트 코드는 뭐 아주 간단한 파이썬 취약성 루틴의 대표적인.. while안에서 덧셈하기.. 흐흐;;
>>> def test():
... x = 0
... while x < 1000000:
... x += 1
... return x
...
결과는
Iron Python 0.6
CPython 2.3
CPython 2.4
0.972
0.625
0.595
아아. 아쉽게도(?) CPython이 간단한 루틴에서는 더 빠르군요. ;; (기분이 묘하다..)
그리고, .NET 클래스 라이브러리 쓰는 것도 어느정도 잘 되는 듯 합니다.
>>> from System import Console
>>> dir(Console)
['Equals', 'Error', 'GetHashCode', 'GetType', 'In', 'OpenStandardError',
'OpenStandardInput', 'OpenStandardOutput', 'Out', 'Read', 'ReadLine', 'SetError',
'SetIn', 'SetOut', 'ToString', 'Write', 'WriteLine', '__new__', 'get_Error',
'get_In', 'get_Out']
>>> Console.Out.WriteLine("hahaha")
True
괜히 제가 만든 mono cp949 코덱 시험도 한번 –;
>>> Text.Encoding.GetEncoding(949)
<I18N.CJK.CP949 object at 0x0E97A400>
>>> _.GetDecoder()
<I18N.CJK.CP949+CP949Decoder object at 0x4D7971E2>
>>> cp949dec = _
>>> dir(cp949dec)
['Equals', 'GetCharCount', 'GetChars', 'GetHashCode', 'GetType', 'ToString', '__new__']
>>> cp949dec.GetChars("하하", 0, 4)
System.Exception: bad args to this method <method# GetChars on I18N.CJK.CP949+CP949Decoder>
in <0x0019c> IronPython.Objects.ReflectedMethodBase:Call (object[])
in <0x00229> IronPython.Objects.Ops:Call (object,object,object,object)
in <0x0006b> input_8:Run (IronPython.Objects.Frame)
in <0x001c5> IronPythonConsole.IronPython:DoInteractive ()
System.Text.Decoder.GetChars의 마지막 2 인자를 어레이랑 어레이 인덱스로 줘야하는데, 어레이를 파이썬에서 어떻게 주는지 알 수가 없어서 일단은 –;;;;;