Skip to content

Instantly share code, notes, and snippets.

@sile
Created May 17, 2014 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sile/64ff1b36ca0cf6dfbb93 to your computer and use it in GitHub Desktop.
Save sile/64ff1b36ca0cf6dfbb93 to your computer and use it in GitHub Desktop.
Erlangコード最適化メモ: JSONデコード処理(2): HiPEを使う ref: http://qiita.com/sile/items/b7aa22a79ac3785736fa
$ erl
Erlang R16B03-1 (erts-5.10.4) [source] [64-bit] [smp:2:2] [async-threads:10] [hipe]
Eshell V5.10.4 (abort with ^G)
%% nativeをコンパイルオプションに、指定するとHiPEコンパイラが使われる
> c(hoge, [native]).
{ok, hoge}.
%% hipe:help/0 でヘルプが表示できる
> hipe:help().
The HiPE Compiler (Version 3.10.2.2)
The normal way to native-compile Erlang code using HiPE is to
include `native' in the Erlang compiler options, as in:
1> c(my_module, [native]).
Options to the HiPE compiler must then be passed as follows:
1> c(my_module, [native,{hipe,Options}]).
Use `help_options()' for details.
Utility functions:
help()
Prints this message.
help_options()
Prints a description of options recognized by the
HiPE compiler.
help_option(Option)
Prints a description of that option.
help_debug_options()
Prints a description of debug options.
version() ->
Returns the HiPE version as a string'.
For HiPE developers only:
Use `help_hiper()' for information about HiPE's low-level interface
ok
%% 最適化レベルが選べたりもする (o3が最高, デフォルトはo2)
> c(hoge, [native, {hipe, [o3]}]).
{ok, hoge}.
%% HiPE無しでコンパイルした場合
> json_decode_1:decode(<<"[1,2,]">>). % 不正なJSONを渡す
** exception error: bad argument
in function json_decode_1:value/1
called as json_decode_1:value(<<"]">>) % 引数情報がつく
in call from json_decode_1:array/2 (json_decode_1.erl, line 44) % 行番号もつく
in call from json_decode_1:decode/1 (json_decode_1.erl, line 18)
%% HiPE有りでコンパイルした場合
> json_decode_1:decode(<<"[1,2,]">>).
** exception error: bad argument
in function json_decode_1_hipe:value/1 % 関数名のみ
in call from json_decode_1_hipe:array/2
in call from json_decode_1_hipe:decode/1
in call from lists:reverse/1 % 何故か経由していないはずの関数が含まれている
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment