使用-j1而不是-jN进行编译有什么好处

时间:2015-05-29 08:48:54

标签: c++ c gcc

使用-jN进行编译会更快编译,因为它会同时编译多个部分。但GCC文档说(虽然我找不到确切的链接),用-j1进行编译会产生更好的优化二进制文件。

您能解释使用-j1进行编译的所有好处吗?您是否可以提供一个小POC,证明使用-j1进行编译会生成比-jN更优化(性能方面)的二进制文件?

2 个答案:

答案 0 :(得分:2)

-j选项适用于make。 gcc

没有这样的选择

我认为你在谈论-O选项。

这是-O1

的手册页
<?php namespace App;

use Illuminate\Database\Eloquent\Model;

class Conference extends Model{

    public function getNameAttribute() {
        return $this->getRelation('event')->name;
    }

    public function event() {
        return $this->belongsTo('App\Event');
    }

    public function speakers() {
        return $this->hasMany('App\Speaker');
    }
}

答案 1 :(得分:1)

您可能正在考虑整个计划优化。当gcc只看到1个文件时,它仅限于它可以优化的内容,因为未知的外部代码可能取决于行为,因此很难完全优化。如果gcc看到整个程序,它可以确切地确定哪些代码取决于什么,允许更好的优化。是否使用-j1让gcc一次编译一个文件或-jN同时编译所有文件没有区别。但是,无论您是让一个实例使用一个调用编译所有内容,还是使用单独调用单独编译每个文件,它确实有所不同。

参考:The compiler performs optimization based on the knowledge it has of the program. Compiling multiple files at once to a single output file mode allows the compiler to use information gained from all of the files when compiling each of them.

相关问题