- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在处理一些繁重的 cpu 绑定(bind)问题。当我使用 inline
时,我看到了很大的性能提升关键词。
我从标准 .net 库中创建了一个字典,传入了一个自定义键比较器,请参见下面的代码和计时结果
https://gist.github.com/4409734
在 Eq_cmp 上没有内联关键字
> perf_run 10000000 ;;
Real: 00:00:11.039, CPU: 00:00:11.029, GC gen0: 771, gen1: 3, gen2: 1
val it : unit = ()
perf_run 10000000 ;;
Real: 00:00:01.319, CPU: 00:00:01.388, GC gen0: 1, gen1: 1, gen2: 1
val it : unit = ()
>
最佳答案
添加 inline
后,我可以在我的机器上以 3 倍的性能提升重现该行为关键词。
在 ILSpy 下并排反编译两个版本给出几乎相同的 C# 代码。显着的区别在于两个相等测试:
// Version without inline
bool IEqualityComparer<Program.Pair<a>>.System-Collections-Generic-IEqualityComparer(Program.Pair<a> x, Program.Pair<a> y)
{
a v@ = x.v@;
a v@2 = y.v@;
if (LanguagePrimitives.HashCompare.GenericEqualityIntrinsic<a>(v@, v@2))
{
a w@ = x.w@;
a w@2 = y.w@;
return LanguagePrimitives.HashCompare.GenericEqualityIntrinsic<a>(w@, w@2);
}
return false;
}
// Version with inline
bool IEqualityComparer<Program.Pair<int>>.System-Collections-Generic-IEqualityComparer(Program.Pair<int> x, Program.Pair<int> y)
{
int v@ = x.v@;
int v@2 = y.v@;
if (v@ == v@2)
{
int w@ = x.w@;
int w@2 = y.w@;
return w@ == w@2;
}
return false;
}
泛型相等的效率远低于专门的版本。
I also noticed the huge difference in the amount of Gen 0 GC with the inlined code and non inlined code.
Could someone explain why there is such a huge difference?
GenericEqualityIntrinsic
F# source code中的函数:
let rec GenericEqualityIntrinsic (x : 'T) (y : 'T) : bool =
fsEqualityComparer.Equals((box x), (box y))
它对参数进行装箱,这解释了您的第一个示例中的大量垃圾。当 GC 过于频繁地发挥作用时,它会显着减慢计算速度。第二个示例(使用
inline
)在
Pair
时几乎不会产生垃圾。是结构。
inline
的预期行为。在调用站点使用专用版本时的关键字。我的建议是始终尝试在相同的基准上优化和衡量您的代码。
关于.net - 为什么 F# inline 会导致 11 倍的性能提升,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14086580/
看看这个 fiddle http://jsfiddle.net/9S4zc/2/ 为什么这在 firefox 和 chrome 中看起来不同(文本对齐方式不同) 如何让 inner:before 元素
我从文档中了解到的是 %{ %} 之间的内容。被插入到包装器中,%inline %{ %} 呢? ? 是一样的吗?如果不是,有什么区别? 也许我们可以找到很多%inline %{ %}的出现。但仅出现
当我使用 显示:inline-flex; 或 显示:内联网格; 似乎有一些额外的“空间”或某种额外的重点计算发生。我不确定到底发生了什么。当使用箭头键在 contentediatble div 中导航
如果我想让一个 div 与容器 div 的其他内联元素内联,而我的目的仅此而已,我应该更喜欢使用 inline-block 或 display property 还是 inline-flex?不能使用
这个问题在这里已经有了答案: Why does an inline-block align to top if it has no content? (2 个答案) 关闭 8 年前。
Ada 信息交换所 states the following : The use of pragma Inline does have its disadvantages. It can create
Name
我问这个基本问题是为了让记录更正。已转介 this question和 its currently accepted answer ,这没有说服力。然而second most voted answer
你好, 在管理面板中,我创建了用于添加产品的表单。表单包括 2 个内联表单集,因为有一些与产品相关的模型。用户可以创建产品,然后定义该产品的不同属性的变体。我将举例说明这一点。用户拥有一个品牌的 3
有很多关于 inline 的使用以及如何正确执行此操作以达到所需目的的信息,例如此处(我目前将其用作引用)Inline Functions in C . 当我尝试实现页面中指定的内容时,出现编译器错误
我正在编写 gtk 代码。我经常有不需要闭包的简短回调,因为它们传递了它们需要的所有参数。例如,我在创建一些 gtk.TreeViewColumns 时将其置于循环中: def widthChange
这个问题在这里已经有了答案: What is the difference between display: inline and display: inline-block? (7 个答案) 关闭
我已经搜索了很长时间来找到答案,但是我没有找到解决方案... 我制作了一个无序列表的链接,并将它们放在标题下,就像导航栏一样。然而,在 IE 中(是的那个恶魔..)我的链接似乎没有对齐到中间。下面是我
我想将两张 table 并排放置。由于我不是 floating 或使用“css hacks”的忠实拥护者,您有什么建议?没有它是否可以解决,还是我运气不好? 最佳答案 使用 table-cell显示以
这个问题在这里已经有了答案: Why is this inline-block element pushed downward? (8 个答案) 关闭 6 年前。
CSS display 的 inline 和 inline-block 值到底有什么区别? 最佳答案 视觉答案 想象一个 中的元素.如果你给 例如,元素高度为 100px 和红色边框,它看起来像这
我想使用 /纯 CSS 弹出窗口的标签,但是 表现为内联 block ,我无法将其更改为内联。 有没有办法强制表现得像 display:inline 而不是 inline-block?
我的想法是这是不可能的,或者我缺少一个额外的步骤。无论哪种方式,我都被卡住了,无法弄清楚。 使用内联模板的原因是能够使用 Laravel Blade 语法并结合 Vue Js 的强大功能。似乎是两者中
http://christianselig.com/wp/ 对于主导航,如果我使用 display: inline,它们将显示为 block 。我心血来潮添加了 display: inline-blo
Firefox 的 -moz-inline-box 和 -moz-inline-stack 专有显示值有什么区别? 最佳答案 https://developer.mozilla.org/en/CSS/
我是一名优秀的程序员,十分优秀!