Error[8]: Undefined offset: 10, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述所以我的问题是为什么让_ =这比这快!= nil? 例: 这是: let this : Bool? = true //let start = DispatchTime.now()for _ in 0...100000000 { guard this != nil else { continue }}let end = DispatchTime.now()let nanoTi 所以我的问题是为什么让_ =这比这快!= nil?

例:

这是:

let this : Bool? = true //let start = dispatchTime.Now()for _ in 0...100000000  {    guard this != nil else { continue }}let end = dispatchTime.Now()let nanoTime = end.uptimeNanoseconds - start.uptimeNanosecondslet timeInterval = Double(nanoTime)print("Time \(timeInterval)")          // Time 5426559135.0         // Time 5428084767.0         // Time 5327325459.0

慢于:

let this : Bool? = true //let start = dispatchTime.Now()for _ in 0...100000000  {    guard let _ = this else { continue }}let end = dispatchTime.Now()let nanoTime = end.uptimeNanoseconds - start.uptimeNanosecondslet timeInterval = Double(nanoTime)print("Time \(timeInterval)")          // Time 257045414.0          // Time 261933863.0          // Time 263465919.0
解决方法 在 Jonathan的 response之后,我检查了实际的反汇编指令.
结果如下:
对于代码:

let this : Bool? = nilthis != nil

我们得到:

0x100001290 <+0>:  pushq  %rbp    0x100001291 <+1>:  movq   %rsp,%rbp    0x100001294 <+4>:  subq   
let this : Bool? = nillet _ = this
x30,%rsp 0x100001298 <+8>: leaq 0x2c7259(%rip),%rdx ; type Metadata for Swift.Bool 0x10000129f <+15>: leaq 0x2b66ca(%rip),%rcx ; protocol witness table for Swift.Bool : Swift.Equatable in Swift 0x1000012a6 <+22>: leaq -0x18(%rbp),%rax 0x1000012aa <+26>: leaq -0x8(%rbp),%r8 0x1000012ae <+30>: movb
0x1000012d0 <+0>:  pushq  %rbp    0x1000012d1 <+1>:  movq   %rsp,%rbp    0x1000012d4 <+4>:  xorl   %eax,%eax    0x1000012d6 <+6>:  movb   
let this : Bool? = nillet _ = this
x2,0x2f93e3(%rip) 0x1000012dd <+13>: movl %edi,-0x4(%rbp) 0x1000012e0 <+16>: movq %rsi,-0x10(%rbp) 0x1000012e4 <+20>: popq %rbp 0x1000012e5 <+21>: retq
x2,0x2f940b(%rip) 0x1000012b5 <+37>: movb 0x2f9404(%rip),%r9b ; test2.this : Swift.Optional<Swift.Bool> 0x1000012bc <+44>: movb %r9b,-0x8(%rbp) 0x1000012c0 <+48>: movb
0x100001490 <+0>:  pushq  %rbp    0x100001491 <+1>:  movq   %rsp,%rbp    0x100001494 <+4>:  movb   
let this : Bool? = nilthis != nil
x2,0x3d9595(%rip) ; gCRAnnotations + 63 0x10000149b <+11>: xorl %eax,%eax 0x10000149d <+13>: popq %rbp 0x10000149e <+14>: retq
x2,-0x10(%rbp) 0x1000012c4 <+52>: movb -0x10(%rbp),%r9b 0x1000012c8 <+56>: movb %r9b,-0x18(%rbp) 0x1000012cc <+60>: movl %edi,-0x1c(%rbp) 0x1000012cf <+63>: movq %r8,%rdi 0x1000012d2 <+66>: movq %rsi,-0x28(%rbp) 0x1000012d6 <+70>: movq %rax,%rsi 0x1000012d9 <+73>: callq 0x10004df10 ; Swift.!= infix <A where A: Swift.Equatable> (Swift.Optional<A>,Swift.Optional<A>) -> Swift.Bool 0x1000012de <+78>: xorl %r10d,%r10d 0x1000012e1 <+81>: movb %al,-0x29(%rbp) 0x1000012e4 <+84>: movl %r10d,%eax 0x1000012e7 <+87>: addq
0x100001490 <+0>:  pushq  %rbp    0x100001491 <+1>:  movq   %rsp,%eax    0x10000149d <+13>: popq   %rbp    0x10000149e <+14>: retq
x30,%rsp 0x1000012eb <+91>: popq %rbp 0x1000012ec <+92>: retq

并为:

[+++]

有:

[+++]

另外,谢谢Code Different指向优化级别.

将值从[-Onone]更改为[-O -whole-module-optimization]将导致生成的asm按以下方式更改:

[+++]

具有

[+++]

[+++]

[+++]

所以结果指令实际上是相同的,执行它们的时间应该非常接近.

总结

以上是内存溢出为你收集整理的ios – 在Swift中,为什么“让_ = this”比“this!= nil”更快?全部内容,希望文章能够帮你解决ios – 在Swift中,为什么“让_ = this”比“this!= nil”更快?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 165, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 11, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述所以我的问题是为什么让_ =这比这快!= nil? 例: 这是: let this : Bool? = true //let start = DispatchTime.now()for _ in 0...100000000 { guard this != nil else { continue }}let end = DispatchTime.now()let nanoTi 所以我的问题是为什么让_ =这比这快!= nil?

例:

这是:

let this : Bool? = true //let start = dispatchTime.Now()for _ in 0...100000000  {    guard this != nil else { continue }}let end = dispatchTime.Now()let nanoTime = end.uptimeNanoseconds - start.uptimeNanosecondslet timeInterval = Double(nanoTime)print("Time \(timeInterval)")          // Time 5426559135.0         // Time 5428084767.0         // Time 5327325459.0

慢于:

let this : Bool? = true //let start = dispatchTime.Now()for _ in 0...100000000  {    guard let _ = this else { continue }}let end = dispatchTime.Now()let nanoTime = end.uptimeNanoseconds - start.uptimeNanosecondslet timeInterval = Double(nanoTime)print("Time \(timeInterval)")          // Time 257045414.0          // Time 261933863.0          // Time 263465919.0
解决方法 在 Jonathan的 response之后,我检查了实际的反汇编指令.
结果如下:
对于代码:

let this : Bool? = nilthis != nil

我们得到:

0x100001290 <+0>:  pushq  %rbp    0x100001291 <+1>:  movq   %rsp,%rbp    0x100001294 <+4>:  subq   
let this : Bool? = nillet _ = this
x30,%rsp 0x100001298 <+8>: leaq 0x2c7259(%rip),%rdx ; type Metadata for Swift.Bool 0x10000129f <+15>: leaq 0x2b66ca(%rip),%rcx ; protocol witness table for Swift.Bool : Swift.Equatable in Swift 0x1000012a6 <+22>: leaq -0x18(%rbp),%rax 0x1000012aa <+26>: leaq -0x8(%rbp),%r8 0x1000012ae <+30>: movb
0x1000012d0 <+0>:  pushq  %rbp    0x1000012d1 <+1>:  movq   %rsp,%rbp    0x1000012d4 <+4>:  xorl   %eax,%eax    0x1000012d6 <+6>:  movb   
let this : Bool? = nillet _ = this
x2,0x2f93e3(%rip) 0x1000012dd <+13>: movl %edi,-0x4(%rbp) 0x1000012e0 <+16>: movq %rsi,-0x10(%rbp) 0x1000012e4 <+20>: popq %rbp 0x1000012e5 <+21>: retq
x2,0x2f940b(%rip) 0x1000012b5 <+37>: movb 0x2f9404(%rip),%r9b ; test2.this : Swift.Optional<Swift.Bool> 0x1000012bc <+44>: movb %r9b,-0x8(%rbp) 0x1000012c0 <+48>: movb
0x100001490 <+0>:  pushq  %rbp    0x100001491 <+1>:  movq   %rsp,%rbp    0x100001494 <+4>:  movb   
let this : Bool? = nilthis != nil
x2,0x3d9595(%rip) ; gCRAnnotations + 63 0x10000149b <+11>: xorl %eax,%eax 0x10000149d <+13>: popq %rbp 0x10000149e <+14>: retq
x2,-0x10(%rbp) 0x1000012c4 <+52>: movb -0x10(%rbp),%r9b 0x1000012c8 <+56>: movb %r9b,-0x18(%rbp) 0x1000012cc <+60>: movl %edi,-0x1c(%rbp) 0x1000012cf <+63>: movq %r8,%rdi 0x1000012d2 <+66>: movq %rsi,-0x28(%rbp) 0x1000012d6 <+70>: movq %rax,%rsi 0x1000012d9 <+73>: callq 0x10004df10 ; Swift.!= infix <A where A: Swift.Equatable> (Swift.Optional<A>,Swift.Optional<A>) -> Swift.Bool 0x1000012de <+78>: xorl %r10d,%r10d 0x1000012e1 <+81>: movb %al,-0x29(%rbp) 0x1000012e4 <+84>: movl %r10d,%eax 0x1000012e7 <+87>: addq
0x100001490 <+0>:  pushq  %rbp    0x100001491 <+1>:  movq   %rsp,%eax    0x10000149d <+13>: popq   %rbp    0x10000149e <+14>: retq
x30,%rsp 0x1000012eb <+91>: popq %rbp 0x1000012ec <+92>: retq

并为:

有:

[+++]

另外,谢谢Code Different指向优化级别.

将值从[-Onone]更改为[-O -whole-module-optimization]将导致生成的asm按以下方式更改:

[+++]

具有

[+++]

[+++]

[+++]

所以结果指令实际上是相同的,执行它们的时间应该非常接近.

总结

以上是内存溢出为你收集整理的ios – 在Swift中,为什么“让_ = this”比“this!= nil”更快?全部内容,希望文章能够帮你解决ios – 在Swift中,为什么“让_ = this”比“this!= nil”更快?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 165, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 12, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述所以我的问题是为什么让_ =这比这快!= nil? 例: 这是: let this : Bool? = true //let start = DispatchTime.now()for _ in 0...100000000 { guard this != nil else { continue }}let end = DispatchTime.now()let nanoTi 所以我的问题是为什么让_ =这比这快!= nil?

例:

这是:

let this : Bool? = true //let start = dispatchTime.Now()for _ in 0...100000000  {    guard this != nil else { continue }}let end = dispatchTime.Now()let nanoTime = end.uptimeNanoseconds - start.uptimeNanosecondslet timeInterval = Double(nanoTime)print("Time \(timeInterval)")          // Time 5426559135.0         // Time 5428084767.0         // Time 5327325459.0

慢于:

let this : Bool? = true //let start = dispatchTime.Now()for _ in 0...100000000  {    guard let _ = this else { continue }}let end = dispatchTime.Now()let nanoTime = end.uptimeNanoseconds - start.uptimeNanosecondslet timeInterval = Double(nanoTime)print("Time \(timeInterval)")          // Time 257045414.0          // Time 261933863.0          // Time 263465919.0
解决方法 在 Jonathan的 response之后,我检查了实际的反汇编指令.
结果如下:
对于代码:

let this : Bool? = nilthis != nil

我们得到:

0x100001290 <+0>:  pushq  %rbp    0x100001291 <+1>:  movq   %rsp,%rbp    0x100001294 <+4>:  subq   
let this : Bool? = nillet _ = this
x30,%rsp 0x100001298 <+8>: leaq 0x2c7259(%rip),%rdx ; type Metadata for Swift.Bool 0x10000129f <+15>: leaq 0x2b66ca(%rip),%rcx ; protocol witness table for Swift.Bool : Swift.Equatable in Swift 0x1000012a6 <+22>: leaq -0x18(%rbp),%rax 0x1000012aa <+26>: leaq -0x8(%rbp),%r8 0x1000012ae <+30>: movb
0x1000012d0 <+0>:  pushq  %rbp    0x1000012d1 <+1>:  movq   %rsp,%rbp    0x1000012d4 <+4>:  xorl   %eax,%eax    0x1000012d6 <+6>:  movb   
let this : Bool? = nillet _ = this
x2,0x2f93e3(%rip) 0x1000012dd <+13>: movl %edi,-0x4(%rbp) 0x1000012e0 <+16>: movq %rsi,-0x10(%rbp) 0x1000012e4 <+20>: popq %rbp 0x1000012e5 <+21>: retq
x2,0x2f940b(%rip) 0x1000012b5 <+37>: movb 0x2f9404(%rip),%r9b ; test2.this : Swift.Optional<Swift.Bool> 0x1000012bc <+44>: movb %r9b,-0x8(%rbp) 0x1000012c0 <+48>: movb
0x100001490 <+0>:  pushq  %rbp    0x100001491 <+1>:  movq   %rsp,%rbp    0x100001494 <+4>:  movb   
let this : Bool? = nilthis != nil
x2,0x3d9595(%rip) ; gCRAnnotations + 63 0x10000149b <+11>: xorl %eax,%eax 0x10000149d <+13>: popq %rbp 0x10000149e <+14>: retq
x2,-0x10(%rbp) 0x1000012c4 <+52>: movb -0x10(%rbp),%r9b 0x1000012c8 <+56>: movb %r9b,-0x18(%rbp) 0x1000012cc <+60>: movl %edi,-0x1c(%rbp) 0x1000012cf <+63>: movq %r8,%rdi 0x1000012d2 <+66>: movq %rsi,-0x28(%rbp) 0x1000012d6 <+70>: movq %rax,%rsi 0x1000012d9 <+73>: callq 0x10004df10 ; Swift.!= infix <A where A: Swift.Equatable> (Swift.Optional<A>,Swift.Optional<A>) -> Swift.Bool 0x1000012de <+78>: xorl %r10d,%r10d 0x1000012e1 <+81>: movb %al,-0x29(%rbp) 0x1000012e4 <+84>: movl %r10d,%eax 0x1000012e7 <+87>: addq
0x100001490 <+0>:  pushq  %rbp    0x100001491 <+1>:  movq   %rsp,%eax    0x10000149d <+13>: popq   %rbp    0x10000149e <+14>: retq
x30,%rsp 0x1000012eb <+91>: popq %rbp 0x1000012ec <+92>: retq

并为:

有:

另外,谢谢Code Different指向优化级别.

将值从[-Onone]更改为[-O -whole-module-optimization]将导致生成的asm按以下方式更改:

[+++]

具有

[+++]

[+++]

[+++]

所以结果指令实际上是相同的,执行它们的时间应该非常接近.

总结

以上是内存溢出为你收集整理的ios – 在Swift中,为什么“让_ = this”比“this!= nil”更快?全部内容,希望文章能够帮你解决ios – 在Swift中,为什么“让_ = this”比“this!= nil”更快?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 165, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 13, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述所以我的问题是为什么让_ =这比这快!= nil? 例: 这是: let this : Bool? = true //let start = DispatchTime.now()for _ in 0...100000000 { guard this != nil else { continue }}let end = DispatchTime.now()let nanoTi 所以我的问题是为什么让_ =这比这快!= nil?

例:

这是:

let this : Bool? = true //let start = dispatchTime.Now()for _ in 0...100000000  {    guard this != nil else { continue }}let end = dispatchTime.Now()let nanoTime = end.uptimeNanoseconds - start.uptimeNanosecondslet timeInterval = Double(nanoTime)print("Time \(timeInterval)")          // Time 5426559135.0         // Time 5428084767.0         // Time 5327325459.0

慢于:

let this : Bool? = true //let start = dispatchTime.Now()for _ in 0...100000000  {    guard let _ = this else { continue }}let end = dispatchTime.Now()let nanoTime = end.uptimeNanoseconds - start.uptimeNanosecondslet timeInterval = Double(nanoTime)print("Time \(timeInterval)")          // Time 257045414.0          // Time 261933863.0          // Time 263465919.0
解决方法 在 Jonathan的 response之后,我检查了实际的反汇编指令.
结果如下:
对于代码:

let this : Bool? = nilthis != nil

我们得到:

0x100001290 <+0>:  pushq  %rbp    0x100001291 <+1>:  movq   %rsp,%rbp    0x100001294 <+4>:  subq   
let this : Bool? = nillet _ = this
x30,%rsp 0x100001298 <+8>: leaq 0x2c7259(%rip),%rdx ; type Metadata for Swift.Bool 0x10000129f <+15>: leaq 0x2b66ca(%rip),%rcx ; protocol witness table for Swift.Bool : Swift.Equatable in Swift 0x1000012a6 <+22>: leaq -0x18(%rbp),%rax 0x1000012aa <+26>: leaq -0x8(%rbp),%r8 0x1000012ae <+30>: movb
0x1000012d0 <+0>:  pushq  %rbp    0x1000012d1 <+1>:  movq   %rsp,%rbp    0x1000012d4 <+4>:  xorl   %eax,%eax    0x1000012d6 <+6>:  movb   
let this : Bool? = nillet _ = this
x2,0x2f93e3(%rip) 0x1000012dd <+13>: movl %edi,-0x4(%rbp) 0x1000012e0 <+16>: movq %rsi,-0x10(%rbp) 0x1000012e4 <+20>: popq %rbp 0x1000012e5 <+21>: retq
x2,0x2f940b(%rip) 0x1000012b5 <+37>: movb 0x2f9404(%rip),%r9b ; test2.this : Swift.Optional<Swift.Bool> 0x1000012bc <+44>: movb %r9b,-0x8(%rbp) 0x1000012c0 <+48>: movb
0x100001490 <+0>:  pushq  %rbp    0x100001491 <+1>:  movq   %rsp,%rbp    0x100001494 <+4>:  movb   
let this : Bool? = nilthis != nil
x2,0x3d9595(%rip) ; gCRAnnotations + 63 0x10000149b <+11>: xorl %eax,%eax 0x10000149d <+13>: popq %rbp 0x10000149e <+14>: retq
x2,-0x10(%rbp) 0x1000012c4 <+52>: movb -0x10(%rbp),%r9b 0x1000012c8 <+56>: movb %r9b,-0x18(%rbp) 0x1000012cc <+60>: movl %edi,-0x1c(%rbp) 0x1000012cf <+63>: movq %r8,%rdi 0x1000012d2 <+66>: movq %rsi,-0x28(%rbp) 0x1000012d6 <+70>: movq %rax,%rsi 0x1000012d9 <+73>: callq 0x10004df10 ; Swift.!= infix <A where A: Swift.Equatable> (Swift.Optional<A>,Swift.Optional<A>) -> Swift.Bool 0x1000012de <+78>: xorl %r10d,%r10d 0x1000012e1 <+81>: movb %al,-0x29(%rbp) 0x1000012e4 <+84>: movl %r10d,%eax 0x1000012e7 <+87>: addq
0x100001490 <+0>:  pushq  %rbp    0x100001491 <+1>:  movq   %rsp,%eax    0x10000149d <+13>: popq   %rbp    0x10000149e <+14>: retq
x30,%rsp 0x1000012eb <+91>: popq %rbp 0x1000012ec <+92>: retq

并为:

有:

另外,谢谢Code Different指向优化级别.

将值从[-Onone]更改为[-O -whole-module-optimization]将导致生成的asm按以下方式更改:

具有

[+++]

[+++]

[+++]

所以结果指令实际上是相同的,执行它们的时间应该非常接近.

总结

以上是内存溢出为你收集整理的ios – 在Swift中,为什么“让_ = this”比“this!= nil”更快?全部内容,希望文章能够帮你解决ios – 在Swift中,为什么“让_ = this”比“this!= nil”更快?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 165, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 14, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述所以我的问题是为什么让_ =这比这快!= nil? 例: 这是: let this : Bool? = true //let start = DispatchTime.now()for _ in 0...100000000 { guard this != nil else { continue }}let end = DispatchTime.now()let nanoTi 所以我的问题是为什么让_ =这比这快!= nil?

例:

这是:

let this : Bool? = true //let start = dispatchTime.Now()for _ in 0...100000000  {    guard this != nil else { continue }}let end = dispatchTime.Now()let nanoTime = end.uptimeNanoseconds - start.uptimeNanosecondslet timeInterval = Double(nanoTime)print("Time \(timeInterval)")          // Time 5426559135.0         // Time 5428084767.0         // Time 5327325459.0

慢于:

let this : Bool? = true //let start = dispatchTime.Now()for _ in 0...100000000  {    guard let _ = this else { continue }}let end = dispatchTime.Now()let nanoTime = end.uptimeNanoseconds - start.uptimeNanosecondslet timeInterval = Double(nanoTime)print("Time \(timeInterval)")          // Time 257045414.0          // Time 261933863.0          // Time 263465919.0
解决方法 在 Jonathan的 response之后,我检查了实际的反汇编指令.
结果如下:
对于代码:

let this : Bool? = nilthis != nil

我们得到:

0x100001290 <+0>:  pushq  %rbp    0x100001291 <+1>:  movq   %rsp,%rbp    0x100001294 <+4>:  subq   
let this : Bool? = nillet _ = this
x30,%rsp 0x100001298 <+8>: leaq 0x2c7259(%rip),%rdx ; type Metadata for Swift.Bool 0x10000129f <+15>: leaq 0x2b66ca(%rip),%rcx ; protocol witness table for Swift.Bool : Swift.Equatable in Swift 0x1000012a6 <+22>: leaq -0x18(%rbp),%rax 0x1000012aa <+26>: leaq -0x8(%rbp),%r8 0x1000012ae <+30>: movb
0x1000012d0 <+0>:  pushq  %rbp    0x1000012d1 <+1>:  movq   %rsp,%rbp    0x1000012d4 <+4>:  xorl   %eax,%eax    0x1000012d6 <+6>:  movb   
let this : Bool? = nillet _ = this
x2,0x2f93e3(%rip) 0x1000012dd <+13>: movl %edi,-0x4(%rbp) 0x1000012e0 <+16>: movq %rsi,-0x10(%rbp) 0x1000012e4 <+20>: popq %rbp 0x1000012e5 <+21>: retq
x2,0x2f940b(%rip) 0x1000012b5 <+37>: movb 0x2f9404(%rip),%r9b ; test2.this : Swift.Optional<Swift.Bool> 0x1000012bc <+44>: movb %r9b,-0x8(%rbp) 0x1000012c0 <+48>: movb
0x100001490 <+0>:  pushq  %rbp    0x100001491 <+1>:  movq   %rsp,%rbp    0x100001494 <+4>:  movb   
let this : Bool? = nilthis != nil
x2,0x3d9595(%rip) ; gCRAnnotations + 63 0x10000149b <+11>: xorl %eax,%eax 0x10000149d <+13>: popq %rbp 0x10000149e <+14>: retq
x2,-0x10(%rbp) 0x1000012c4 <+52>: movb -0x10(%rbp),%r9b 0x1000012c8 <+56>: movb %r9b,-0x18(%rbp) 0x1000012cc <+60>: movl %edi,-0x1c(%rbp) 0x1000012cf <+63>: movq %r8,%rdi 0x1000012d2 <+66>: movq %rsi,-0x28(%rbp) 0x1000012d6 <+70>: movq %rax,%rsi 0x1000012d9 <+73>: callq 0x10004df10 ; Swift.!= infix <A where A: Swift.Equatable> (Swift.Optional<A>,Swift.Optional<A>) -> Swift.Bool 0x1000012de <+78>: xorl %r10d,%r10d 0x1000012e1 <+81>: movb %al,-0x29(%rbp) 0x1000012e4 <+84>: movl %r10d,%eax 0x1000012e7 <+87>: addq
0x100001490 <+0>:  pushq  %rbp    0x100001491 <+1>:  movq   %rsp,%eax    0x10000149d <+13>: popq   %rbp    0x10000149e <+14>: retq
x30,%rsp 0x1000012eb <+91>: popq %rbp 0x1000012ec <+92>: retq

并为:

有:

另外,谢谢Code Different指向优化级别.

将值从[-Onone]更改为[-O -whole-module-optimization]将导致生成的asm按以下方式更改:

具有

[+++]

[+++]

所以结果指令实际上是相同的,执行它们的时间应该非常接近.

总结

以上是内存溢出为你收集整理的ios – 在Swift中,为什么“让_ = this”比“this!= nil”更快?全部内容,希望文章能够帮你解决ios – 在Swift中,为什么“让_ = this”比“this!= nil”更快?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 165, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 15, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述所以我的问题是为什么让_ =这比这快!= nil? 例: 这是: let this : Bool? = true //let start = DispatchTime.now()for _ in 0...100000000 { guard this != nil else { continue }}let end = DispatchTime.now()let nanoTi 所以我的问题是为什么让_ =这比这快!= nil?

例:

这是:

let this : Bool? = true //let start = dispatchTime.Now()for _ in 0...100000000  {    guard this != nil else { continue }}let end = dispatchTime.Now()let nanoTime = end.uptimeNanoseconds - start.uptimeNanosecondslet timeInterval = Double(nanoTime)print("Time \(timeInterval)")          // Time 5426559135.0         // Time 5428084767.0         // Time 5327325459.0

慢于:

let this : Bool? = true //let start = dispatchTime.Now()for _ in 0...100000000  {    guard let _ = this else { continue }}let end = dispatchTime.Now()let nanoTime = end.uptimeNanoseconds - start.uptimeNanosecondslet timeInterval = Double(nanoTime)print("Time \(timeInterval)")          // Time 257045414.0          // Time 261933863.0          // Time 263465919.0
解决方法 在 Jonathan的 response之后,我检查了实际的反汇编指令.
结果如下:
对于代码:

let this : Bool? = nilthis != nil

我们得到:

0x100001290 <+0>:  pushq  %rbp    0x100001291 <+1>:  movq   %rsp,%rbp    0x100001294 <+4>:  subq   
let this : Bool? = nillet _ = this
x30,%rsp 0x100001298 <+8>: leaq 0x2c7259(%rip),%rdx ; type Metadata for Swift.Bool 0x10000129f <+15>: leaq 0x2b66ca(%rip),%rcx ; protocol witness table for Swift.Bool : Swift.Equatable in Swift 0x1000012a6 <+22>: leaq -0x18(%rbp),%rax 0x1000012aa <+26>: leaq -0x8(%rbp),%r8 0x1000012ae <+30>: movb
0x1000012d0 <+0>:  pushq  %rbp    0x1000012d1 <+1>:  movq   %rsp,%rbp    0x1000012d4 <+4>:  xorl   %eax,%eax    0x1000012d6 <+6>:  movb   
let this : Bool? = nillet _ = this
x2,0x2f93e3(%rip) 0x1000012dd <+13>: movl %edi,-0x4(%rbp) 0x1000012e0 <+16>: movq %rsi,-0x10(%rbp) 0x1000012e4 <+20>: popq %rbp 0x1000012e5 <+21>: retq
x2,0x2f940b(%rip) 0x1000012b5 <+37>: movb 0x2f9404(%rip),%r9b ; test2.this : Swift.Optional<Swift.Bool> 0x1000012bc <+44>: movb %r9b,-0x8(%rbp) 0x1000012c0 <+48>: movb
0x100001490 <+0>:  pushq  %rbp    0x100001491 <+1>:  movq   %rsp,%rbp    0x100001494 <+4>:  movb   
let this : Bool? = nilthis != nil
x2,0x3d9595(%rip) ; gCRAnnotations + 63 0x10000149b <+11>: xorl %eax,%eax 0x10000149d <+13>: popq %rbp 0x10000149e <+14>: retq
x2,-0x10(%rbp) 0x1000012c4 <+52>: movb -0x10(%rbp),%r9b 0x1000012c8 <+56>: movb %r9b,-0x18(%rbp) 0x1000012cc <+60>: movl %edi,-0x1c(%rbp) 0x1000012cf <+63>: movq %r8,%rdi 0x1000012d2 <+66>: movq %rsi,-0x28(%rbp) 0x1000012d6 <+70>: movq %rax,%rsi 0x1000012d9 <+73>: callq 0x10004df10 ; Swift.!= infix <A where A: Swift.Equatable> (Swift.Optional<A>,Swift.Optional<A>) -> Swift.Bool 0x1000012de <+78>: xorl %r10d,%r10d 0x1000012e1 <+81>: movb %al,-0x29(%rbp) 0x1000012e4 <+84>: movl %r10d,%eax 0x1000012e7 <+87>: addq
0x100001490 <+0>:  pushq  %rbp    0x100001491 <+1>:  movq   %rsp,%eax    0x10000149d <+13>: popq   %rbp    0x10000149e <+14>: retq
x30,%rsp 0x1000012eb <+91>: popq %rbp 0x1000012ec <+92>: retq

并为:

有:

另外,谢谢Code Different指向优化级别.

将值从[-Onone]更改为[-O -whole-module-optimization]将导致生成的asm按以下方式更改:

具有

[+++]

所以结果指令实际上是相同的,执行它们的时间应该非常接近.

总结

以上是内存溢出为你收集整理的ios – 在Swift中,为什么“让_ = this”比“this!= nil”更快?全部内容,希望文章能够帮你解决ios – 在Swift中,为什么“让_ = this”比“this!= nil”更快?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 165, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
ios – 在Swift中,为什么“让_ = this”比“this!= nil”更快?_app_内存溢出

ios – 在Swift中,为什么“让_ = this”比“this!= nil”更快?

ios – 在Swift中,为什么“让_ = this”比“this!= nil”更快?,第1张

概述所以我的问题是为什么让_ =这比这快!= nil? 例: 这是: let this : Bool? = true //let start = DispatchTime.now()for _ in 0...100000000 { guard this != nil else { continue }}let end = DispatchTime.now()let nanoTi 所以我的问题是为什么让_ =这比这快!= nil?

例:

这是:

let this : Bool? = true //let start = dispatchTime.Now()for _ in 0...100000000  {    guard this != nil else { continue }}let end = dispatchTime.Now()let nanoTime = end.uptimeNanoseconds - start.uptimeNanosecondslet timeInterval = Double(nanoTime)print("Time \(timeInterval)")          // Time 5426559135.0         // Time 5428084767.0         // Time 5327325459.0

慢于:

let this : Bool? = true //let start = dispatchTime.Now()for _ in 0...100000000  {    guard let _ = this else { continue }}let end = dispatchTime.Now()let nanoTime = end.uptimeNanoseconds - start.uptimeNanosecondslet timeInterval = Double(nanoTime)print("Time \(timeInterval)")          // Time 257045414.0          // Time 261933863.0          // Time 263465919.0
解决方法 在 Jonathan的 response之后,我检查了实际的反汇编指令.
结果如下:
对于代码:

let this : Bool? = nilthis != nil

我们得到:

0x100001290 <+0>:  pushq  %rbp    0x100001291 <+1>:  movq   %rsp,%rbp    0x100001294 <+4>:  subq   
let this : Bool? = nillet _ = this
x30,%rsp 0x100001298 <+8>: leaq 0x2c7259(%rip),%rdx ; type Metadata for Swift.Bool 0x10000129f <+15>: leaq 0x2b66ca(%rip),%rcx ; protocol witness table for Swift.Bool : Swift.Equatable in Swift 0x1000012a6 <+22>: leaq -0x18(%rbp),%rax 0x1000012aa <+26>: leaq -0x8(%rbp),%r8 0x1000012ae <+30>: movb
0x1000012d0 <+0>:  pushq  %rbp    0x1000012d1 <+1>:  movq   %rsp,%rbp    0x1000012d4 <+4>:  xorl   %eax,%eax    0x1000012d6 <+6>:  movb   
let this : Bool? = nillet _ = this
x2,0x2f93e3(%rip) 0x1000012dd <+13>: movl %edi,-0x4(%rbp) 0x1000012e0 <+16>: movq %rsi,-0x10(%rbp) 0x1000012e4 <+20>: popq %rbp 0x1000012e5 <+21>: retq
x2,0x2f940b(%rip) 0x1000012b5 <+37>: movb 0x2f9404(%rip),%r9b ; test2.this : Swift.Optional<Swift.Bool> 0x1000012bc <+44>: movb %r9b,-0x8(%rbp) 0x1000012c0 <+48>: movb
0x100001490 <+0>:  pushq  %rbp    0x100001491 <+1>:  movq   %rsp,%rbp    0x100001494 <+4>:  movb   
let this : Bool? = nilthis != nil
x2,0x3d9595(%rip) ; gCRAnnotations + 63 0x10000149b <+11>: xorl %eax,%eax 0x10000149d <+13>: popq %rbp 0x10000149e <+14>: retq
x2,-0x10(%rbp) 0x1000012c4 <+52>: movb -0x10(%rbp),%r9b 0x1000012c8 <+56>: movb %r9b,-0x18(%rbp) 0x1000012cc <+60>: movl %edi,-0x1c(%rbp) 0x1000012cf <+63>: movq %r8,%rdi 0x1000012d2 <+66>: movq %rsi,-0x28(%rbp) 0x1000012d6 <+70>: movq %rax,%rsi 0x1000012d9 <+73>: callq 0x10004df10 ; Swift.!= infix <A where A: Swift.Equatable> (Swift.Optional<A>,Swift.Optional<A>) -> Swift.Bool 0x1000012de <+78>: xorl %r10d,%r10d 0x1000012e1 <+81>: movb %al,-0x29(%rbp) 0x1000012e4 <+84>: movl %r10d,%eax 0x1000012e7 <+87>: addq
0x100001490 <+0>:  pushq  %rbp    0x100001491 <+1>:  movq   %rsp,%eax    0x10000149d <+13>: popq   %rbp    0x10000149e <+14>: retq
x30,%rsp 0x1000012eb <+91>: popq %rbp 0x1000012ec <+92>: retq

并为:

有:

另外,谢谢Code Different指向优化级别.

将值从[-Onone]更改为[-O -whole-module-optimization]将导致生成的asm按以下方式更改:

具有

所以结果指令实际上是相同的,执行它们的时间应该非常接近.

总结

以上是内存溢出为你收集整理的ios – 在Swift中,为什么“让_ = this”比“this!= nil”更快?全部内容,希望文章能够帮你解决ios – 在Swift中,为什么“让_ = this”比“this!= nil”更快?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1056995.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存