MRI (the main ruby interpreter) has an odd string representation that's optimized for shorter strings. There's some info here: [ http://patshaughnessy.net/2012/1/4/never-create-ruby-strings-longer-than-23-characters]. The type is defined here: [ https://github.com/ruby/ruby/blob/af18eafc44bb3bb6aff78f244a67b807500e3e9f/include/ruby/ruby.h#L979 ].
-J On Sun, Jan 17, 2016 at 3:08 PM, Robby Findler <[email protected]> wrote: > Do we know if ruby represents strings the same way Racket does? The > representation in C clearly admits more efficient implementations of > relevant operations here, and Ruby's might too. > > Robby > > > On Sun, Jan 17, 2016 at 2:00 PM, Jon Zeppieri <[email protected]> wrote: > > My string-trim uses unsafe ops, but I'm pretty sure it's safe. The > (safe) string-length at the start ensures we're using a string. The rest > are indexing and fixnum arithmetic on integers that are guaranteed to be > valid indices of the string. > > > > Still, if you don't like this, replace the unsafe ops with the > corresponding safe ones. It will still be much faster than the built-in > version. > > > >> On Jan 17, 2016, at 2:54 PM, Brian Adkins <[email protected]> > wrote: > >> > >>> On Sunday, January 17, 2016 at 2:50:19 PM UTC-5, Brian Adkins wrote: > >>> > >>> With built-in string-trim, the lowest of three runs was 10293. Using > your string-trim the lowest of three runs was 7618, so it reduced the > runtime by 26%. > >> > >> Although, I probably should've mentioned that I'm not particularly > interested in unsafe optimizations. I already have a very fast C program if > I'm willing to risk unsafe behavior, so for Racket, I'd like to retain > safety. > >> > >> Having said that, I'm pretty sure a combination of using Byte Strings > and manually optimizing string-trim & string-replace (or skipping them in > some cases) will get under the Ruby time. > >> > >> -- > >> You received this message because you are subscribed to the Google > Groups "Racket Users" group. > >> To unsubscribe from this group and stop receiving emails from it, send > an email to [email protected]. > >> For more options, visit https://groups.google.com/d/optout. > > > > -- > > You received this message because you are subscribed to the Google > Groups "Racket Users" group. > > To unsubscribe from this group and stop receiving emails from it, send > an email to [email protected]. > > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.

