ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: "Christoph" <chr_news@gmx.net>
To: <ruby-core@ruby-lang.org>
Subject: A truth? patch  + benchmarks
Date: Wed, 31 Jul 2002 23:47:05 +0900	[thread overview]
Message-ID: <000001c238a0$d32538f0$0100a8c0@lony> (raw)
In-Reply-To: <20020726101116.7B7261EE12@milestones.dm4lab.to>

[-- Attachment #1: Type: text/plain, Size: 3072 bytes --]



> -----Original Message-----
> From: YANAGAWA Kazuhisa [mailto:kjana@dm4lab.to]
> Sent: Friday, July 26, 2002 12:11 PM
> To: ruby-core@ruby-lang.org
> Subject: Re: [PATCH] object.c ruby.h (fwd)
> 
> In message <m2bs8vr1h7.fsf@zip.local.thomases.com>
> Dave@PragmaticProgrammer.com writes:
> 
> > So, perhaps, if the expression to pass to 'if', 'while', and friends
> > isn't 'true' or 'false', the interpreter should call #truth? on it
to
> > coerce it into a truth value.[1]
> >
> > If that sounds logical, then perhaps #to_truth might be a more
> > consistent name.
> 
> That's like my old proposal on.... where? :-) Matz rejected that since
> its cost may be too expensive.  So if you state it strongly, show its
> usefulness and effective implementation.

Trying to answer your first question, it seems to me that
Every time you are dealing with the Null-Pattern such a
facility might come in handy. The proliferation of the
``false'' value in Python and indirectly the existence of
the conversion methods #to_something in the NilClass are a
testimony for this.


I also cooked up simple minded an implementation. It is based on
a FL_FALSE flag (I defined it to be 1<<5 not sure if this can
case any problem?) similar to the frozen or tainted flags - that
is I added there methods (the method names ain't great ..)

#falsify : the ``truth-state'' is set to false)
#verify  : the ``truth-state'' is set to true)
#truth?  : tests the truth state.
           obj.truth? returns true if obj is
           an immediate value != false,nil (in other
           words obj is a Symbol, Fixnum or ``True'')
           or obj non immediate object and the false
           flag is not set.


A welcome side affect of this implementation is, that you
cannot change the truth-state of Fixnums and O particular
so Perl fans would be still pissed off;-)).
 

A few words about the included benchmarks.  I pitted
3 type of implementation (and two compilers Mingw32
and VC7) against each other. 

a) Stock Ruby (as of today).
b) The patched Ruby
c) The patched Ruby where I replaced the macro calls 
   RTEST(ruby_debug) and RTEST(rbuy_verbose)
   with PURE_RTEST(ruby_debug) and PURE_RTEST(ruby_verbose)
   macro call - where PURE_TEST is ``original RTEST'' macro.


The first test is a gc and memory intensive problem.
(It is a solution to Tobias Reif [ruby-talk:33425]
maximal anagram chain problem - my wordlist contains
about 230,000 English words).

In this test a) & b) perform about the same but c)
is ~ 10 percent faster.


The second test is the simple ``program flow
test'' (no gc work involved).

---
# loop.rb
require 'benchmark'
include Benchmark


i = 0
bm do |x|
  x.report do
    while (i) do
     i+= 1
     i = nil if i == 5000000
   end
  end
end 
---
 
The result are quite surprising. Both b) and c)
(which is slightly slower in this case) outperform
a) by almost 20 percent.


All in all even if the false flag scheme is
rejected it is probably a good idea to replace
some of the current RTEST(obj) macro calls
with an inlined c-function version.



/Christoph

[-- Attachment #2: bench.tar.gz --]
[-- Type: application/octet-stream, Size: 2182 bytes --]

[-- Attachment #3: patch.tar.gz --]
[-- Type: application/octet-stream, Size: 1037 bytes --]

  reply	other threads:[~2002-07-31 14:46 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-24 15:02 [PATCH] object.c ruby.h (fwd) Robert Skarwecki
2002-07-24 16:51 ` Boolean class (Re: [PATCH] object.c ruby.h) Yukihiro Matsumoto
2002-07-24 19:50 ` [PATCH] object.c ruby.h (fwd) GOTO Kentaro
2002-07-24 20:05   ` Dave Thomas
2002-07-25  4:22     ` unifying nil and false (Re: [PATCH] object.c ruby.h) Yukihiro Matsumoto
2002-07-25  4:59       ` Dave Thomas
2002-07-25  6:46         ` Yukihiro Matsumoto
2002-07-25 11:06     ` [PATCH] object.c ruby.h (fwd) GOTO Kentaro
2002-07-25 13:20       ` Dave Thomas
2002-07-25 17:42         ` nobu.nokada
2002-07-25 17:55           ` Dave Thomas
2002-07-25 18:11             ` nobu.nokada
2002-07-25 18:28               ` Dave Thomas
2002-07-25 19:53               ` GOTO Kentaro
2002-07-25 20:34                 ` Dave Thomas
2002-07-25 22:23                   ` GOTO Kentaro
2002-07-27  8:04                     ` Masaki Suketa
2002-07-27 12:40                       ` Dave Thomas
2002-08-03  9:04                         ` Masaki Suketa
2002-08-05  1:39                           ` NAKAMURA, Hiroshi
2002-08-06 11:53                             ` Masaki Suketa
2002-08-09 13:20                               ` NAKAMURA, Hiroshi
2002-08-10 12:19                                 ` Masaki Suketa
2002-08-12  3:48                                   ` NAKAMURA, Hiroshi
2002-07-26 10:11                   ` YANAGAWA Kazuhisa
2002-07-31 14:47                     ` Christoph [this message]
2002-07-31 15:03                       ` A truth? patch + benchmarks ts
2002-08-01  6:39                         ` Christoph
2002-08-01  7:02                           ` Yukihiro Matsumoto
2002-08-02  7:12                             ` Christoph
2002-08-02  7:20                               ` ts
2002-08-02  8:54                                 ` Christoph
2002-08-03  9:51                               ` Yukihiro Matsumoto
2002-08-05  0:58                                 ` Christoph
2002-08-05  1:44                                   ` nobu.nokada
2002-08-16  6:52               ` Mswin32 build flags Christoph
2002-08-16  7:12                 ` U.Nakamura
2002-09-03 18:51                   ` Christoph
2002-07-26  1:16         ` [PATCH] object.c ruby.h (fwd) NAKAMURA, Hiroshi
2002-07-26 15:23       ` Michal Rokos
2002-07-26 15:31         ` Dave Thomas
2002-07-26 16:37         ` Yukihiro Matsumoto

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='000001c238a0$d32538f0$0100a8c0@lony' \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).