在哪些版本的 ruby​​ 中,外部迭代器速度得到了提高?

发布于 2024-09-06 14:47:18 字数 226 浏览 0 评论 0原文

根据 this ruby​​quiz,外部迭代器过去很慢,但现在更快。这是仅在 YARV(基于 C 的 ruby​​ 1.9 实现)中提供的改进,还是在基于 C 的 ruby​​ 1.8.7 实现中也可用?

另外,enum_for 是否依赖外部迭代器?

According to this rubyquiz, external iterators used to be slow, but are now faster. Is this an improvement only available in YARV (the C-based implementation of ruby 1.9), or is this also available in the C-based implementation of ruby 1.8.7?

Also, does enum_for rely on external iterators?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

叫思念不要吵 2024-09-13 14:47:18

Ruby 1.9 使用纤程来实现 Enumerator#next,这可能比 Ruby 1.8 更好,但仍然是一个昂贵的调用。

enum_for 返回一个 Enumerator 但不依赖外部迭代器。仅在需要时才会创建纤程/延续,即如果您调用 next 但如果您调用 each 或从 Enumerable 继承的任何其他方法则不会创建。

Rubinius 和 JRuby 正在针对内置类型优化 next,因为它非常难以实现,特别是在 JVM 上。有趣的睡前阅读:此线程在 ruby​​ 核心上

Ruby 1.9 uses fibers to implement Enumerator#next, which might be better than Ruby 1.8, but still makes it an expensive call to make.

enum_for returns an Enumerator but does not rely on external iterators. A fiber/continuation will be created only if needed, i.e. if you call next but not if you call each or any other method inherited from Enumerable.

Rubinius and JRuby are optimizing next for the builtin types because it is very difficult to implement, in particular on the JVM. Fun bedtime reading: this thread on ruby-core

烦人精 2024-09-13 14:47:18

Rubinius 还具有一些主要的性能增强,但它是 Ruby 1.8 实现,而不是 1.9。

Rubinius also has some major performance enhancements, but it is a Ruby 1.8 implementation, not 1.9.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文