- 浏览: 59525 次
最近访客 更多访客>>
最新评论
-
healer_kx:
Reading~healer.kx~~~~~~~
编译器的书 -
yawl:
"SVM are some of the most ...
classifier算法优缺点 -
coderplay:
SVM有啥优点? 没整过, 只是知道算法是咋回事. 依算法描述 ...
classifier算法优缺点 -
yawl:
我现在在做sentiment analysis的,看这方面的p ...
classifier算法优缺点 -
luven:
好看不重要,关键看创意!
Rails Rumble -- 48小时内完成的131个 application
[Update 03/12/2007 If you know how to implement Interge#times in pure ruby and make it have the same behavior as Ruby 1.8.5, please let me know. Thank you!]
One of the best things I love about rubinius project is: their developers try to keep the dependency on system language (C in their case) minimal, and they take it seriously. Take a look of http://code.fallingsnow.net/svn/rubinius/trunk/kernel/core/, you will find out lots of buitlin libraries are implemented in pure ruby, even lots of string functions.
Pure ruby builtin has some drawbacks, though. One is performance penalty, the other is potential side effects. For example, basically Integer#times can be implemented as simple as this in pure ruby:
But this version of Integer#times does not work exactly the same as Ruby 1.8.5. If an user want to override Fixnum#+ (this may never happen in real life):
Our Integer#times's behavior will change, while Ruby 1.8.5 won't. That is because Ruby 1.8.5's implementation (int_dotimes() in Numeric.c) optimizes for Fixnum: it does not call '+' method dynamically for Fixnum, instead, it just increases the integer directly. If you want to implement this method as same as Ruby 1.8.5 then you have to write code in system language.
This kind of optimization is all over the place in c ruby. I am not clear about its motivation, but I guess performance is one of the reasons. For example, "30000000.times {|x|}" is about twice faster than "i = 0; while i < 30000000; i +=1; end" in Ruby 1.8.5.
Difference people may have different opinions on what the 'right' behavior should be. As for me, I like the behavior of the pure ruby implementation better.
One of the best things I love about rubinius project is: their developers try to keep the dependency on system language (C in their case) minimal, and they take it seriously. Take a look of http://code.fallingsnow.net/svn/rubinius/trunk/kernel/core/, you will find out lots of buitlin libraries are implemented in pure ruby, even lots of string functions.
Pure ruby builtin has some drawbacks, though. One is performance penalty, the other is potential side effects. For example, basically Integer#times can be implemented as simple as this in pure ruby:
class Integer
def times
i = 0
while i < self
yield i
i += 1;
end
self
end
end
But this version of Integer#times does not work exactly the same as Ruby 1.8.5. If an user want to override Fixnum#+ (this may never happen in real life):
class Fixnum
def + x
return 9999
end
end
Our Integer#times's behavior will change, while Ruby 1.8.5 won't. That is because Ruby 1.8.5's implementation (int_dotimes() in Numeric.c) optimizes for Fixnum: it does not call '+' method dynamically for Fixnum, instead, it just increases the integer directly. If you want to implement this method as same as Ruby 1.8.5 then you have to write code in system language.
This kind of optimization is all over the place in c ruby. I am not clear about its motivation, but I guess performance is one of the reasons. For example, "30000000.times {|x|}" is about twice faster than "i = 0; while i < 30000000; i +=1; end" in Ruby 1.8.5.
Difference people may have different opinions on what the 'right' behavior should be. As for me, I like the behavior of the pure ruby implementation better.
发表评论
-
编译器的书
2008-01-04 01:12 2777有关编译器的书中"Dragon Book" ... -
新的各种ruby实现的性能比较
2007-12-04 06:13 2251Antonio Cangiano今天在blog上更新了各种ru ... -
xruby 0.3.2发布了
2007-11-29 06:00 1521基本和上一个版本(0.3.1)相比变化不大, 大多数都是bug ... -
三周的假期结束了
2007-11-27 20:44 1057用年假回国了一趟。由于时间太短,只在北京和兰州各待了几天。家里 ... -
YAML也要没人维护了
2007-11-05 12:45 1366sishen在xruby mailist提到YAML项目很可能 ... -
Strongtalk项目将无人维护了
2007-11-01 02:05 1940Strongtalk项目的Dave Griswold几天前发了 ... -
和日期相关的库
2007-10-29 22:52 1052上周加入了三个和日期相关的库: time.rb parseda ... -
xruby.googlecode.com
2007-10-23 13:24 1277刚才发现google code最近做了不少改进,其中的就是一个 ... -
复杂的依赖关系
2007-10-19 13:48 1240支持ruby on rails是xruby最重要的目标.我最近 ... -
rails application和web server
2007-10-17 01:31 1380部署到apache/lighthttpd的rails appl ... -
singleton.rb
2007-10-16 00:01 1113上一周的时间,基本上都在争取让xruby能支持singleto ... -
用Jakarta-ORO重写了Regexp
2007-10-10 00:36 2241这个javaeye上的blog本来是利用rss导入做的在国内的 ... -
xruby 0.3.0 released
2007-08-08 05:02 1656I am pleased to announce that X ... -
ruby -y
2007-06-12 15:14 1211For people who are interested i ... -
XRuby 0.2.0 released
2007-05-15 15:15 1137I am glad to announce that XRub ... -
InfoQ article on XRuby
2007-04-17 11:16 874Werner Schuster from InfoQ has ... -
XRuby 0.1.0 released
2007-01-29 22:32 1234[Link of this article: http://x ... -
On-Ruby interview
2007-02-19 03:33 1138Pat Eyler recently interviewed ... -
XRuby 0.1.2 released
2007-03-02 05:58 1204XRuby 0.1.2 is now available fo ... -
XRuby is faster than Ruby 1.8.5 in most benchmarks
2007-03-12 03:02 1698Two weeks ago, Antonio Cangiano ...
相关推荐
TStarBots Defeating the Cheating Level Builtin AI in StarCraft in the full game
unity_builtin_extra
BuiltIn库_Robot framework
Unity内置着色器源码 版本:builtin_shaders-4.1.5.zip
builtin_shaders_源码,builtin_shaders_源码,builtin_shaders_源码,
builtin_shaders-2021
Unity内置着色器源码 版本: builtin_shaders-4.0.1.zip
untiy 2021 内置shader for windows
unity builtin_shaders - unity自带shader源码 Transparent的是alpha开头的
unity-builtin-shader
Unity内置着色器源码 版本: builtin_shaders_2018.4.9f1
builtin_shaders-2020.1.6f1 Unity内置shader
Unity内置着色器源码 版本:builtin_shaders-2018.1.9f2.zip
Unity内置着色器源码 版本:builtin_shaders-5.2.5f1.zip
builtin命令用于执行指定的bash内建命令, builtin命令调用的bash内建命令优先于同名的外部命令及同名的shell函数。 返回该内建命令执行的返回值,除非传递的不是bash内建命令或该内建命令被禁用。 语法格式: ...
Unity内置着色器源码 版本:builtin_shaders-2018.4.22f1.zip Unity内置着色器源码 版本:builtin_shaders-2018.4.22f1.zip
[Electron][JS][教學]_Nodejs基礎#03._require_函數介紹(二),_Builtin_modules
unity2018的shader源码,unity系统内置的各种shader效果,参考学习shader编写
Deep Cover旨在成为Ruby代码的最佳覆盖工具: 更准确的线覆盖 分支机构覆盖 可以用作内置Coverage库的直接替代品。 它报告您的代码使用情况更准确。 特别是,只有且仅在完全执行以下一行时,该行才被视为覆盖: ...