42 ms·
I still don't know "why" even after reading this. The highlighted block of C doesn't tell me anything and neither does the comment on it. As far as I can tell,
by davidcelis 12y ago
I still don't know "why" even after reading this. The highlighted block of C doesn't tell me anything and neither does the comment on it. As far as I can tell, this is just a benchmark with no explanation.
- montanalow 12y agoI'll go edit the post to make it more clear that you need to follow the links through the code to get the actual answer... it's more involved than a single snippet.
- orbitur 12y agoI was about to make the same comment. I'll take a wild stab at why setting/getting `b` is slower. The author of the code has just inserted another call layer by manually defining the getter and setter in Ruby.
- Someone 12y ago"Why attr_reader and attr_writer are faster than def VM_METHOD_TYPE_ATTRSET and VM_METHOD_TYPE_IVAR are the reason attr_accessor is significantly faster than a normal method created with def. These are implemented as pure C functions without creating a new Ruby stack frame, or executing compiled Instruction Sequences inside the VM."