perl - Perl Inline::C default flags
问题描述
I made a module using Inline::C and I noticed some unexpected performance discrepancies between running it on the host MacOS vs a guest Linux VM. Looking into it, it was due to the default C compiler flags being different. On MacOS they appear to be:
-fno-common -DPERL_DARWIN -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -O3 -DVERSION=\"0.00\" -DXS_VERSION=\"0.00\"
Vs on Centos 7:
-fPIC -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -O2 -DVERSION=\"0.00\" -DXS_VERSION=\"0.00\"
The main difference for my code is O3 vs O2, so I looked into the Inline docs and used:
use Inline (C => Config => ccflags => '-O3');
To explicitly specify -O3
. Well, the result is that -O3 -O2
is applied that way, so specifying ccflags does not overwrite the default, it just adds before them, which in the end does not have any effect.
Any idea where the default comes from and/or how to overwrite it to specify the optimization level that I want.
解决方案
似乎添加optimize
配置选项可以满足您的需求。这是一个非常简短的示例,其中包含添加之前optimize => '-O3'
和之后的输出:
use warnings;
use strict;
use Inline 'C';
use Inline C => 'Config',
build_noisy => 1,
force_build => 1,
optimize => '-O3',
;
print add(5, 6);
__END__
__C__
int add (int x, int y){
return(x + y);
}
这是输出(为简洁起见):
前:
cc -c -I"/home/steve/scratch/inline" -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2
后:
cc -c -I"/home/steve/scratch/inline" -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O3
...在 Linux Mint 18.3 上。
默认值来自,它在系统上编译/构建$Config{optimize}
时存储为只读默认值。perl
推荐阅读
- mongodb - SpringBoot Mongorepository 没有正确保存实体属性集
- bash - 会话后不保存 Bash 别名
- dpkg - 如何故意将包配置一半?
- javascript - 合并两个对象,但忽略虚假值
- algorithm - 斐波那契搜索与二分搜索相比的时间复杂度
- python - 如何在 MultiIndex Groupby 中高效地执行乘法
- meson-build - 如何使用介子构建系统将多个转换规则应用于文件列表
- node.js - DiscordJS reactCollector 'remove' 永远不会发出
- python - 使用 Python 进行多处理
- json - 使用 JQ 到特定的 csv 格式