The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Stripping NULL

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Daniel Berger

Posts: 1383
Nickname: djberg96
Registered: Sep, 2004

Daniel Berger is a Ruby Programmer who also dabbles in C and Perl
Stripping NULL Posted: May 18, 2006 10:39 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Daniel Berger.
Original Post: Stripping NULL
Feed Title: Testing 1,2,3...
Feed URL: http://djberg96.livejournal.com/data/rss
Feed Description: A blog on Ruby and other stuff.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Daniel Berger
Latest Posts From Testing 1,2,3...

Advertisement
In our efforts to rewrite win32-eventlog I noticed that the EventLog#read method was rather slow compared to the C equivalent. Too slow, even for pure Ruby. Thanks to the profiler I noticed the primary culprit was this idiom I was using to strip a string of null characters:
string.split(0.chr).first

This was necessary, instead of String#rstrip or String#gsub, because the buffer could contain junk other than null characters at the end of the string. So, I proposed a String#nstrip (null strip) on the ruby-core list, and several people chimed in with some handy, and faster, solutions. The winner was Ara Howard with this solution:
string[ /^[^\0]*/ ]

That's about 4 times faster than the approach I was using, which had quite a significant impact. To give you an idea of just how significant, it took 6 minutes to read 12000 event log records using the old approach. Using Ara's approach reduced that to 2 minutes. :)

Read: Stripping NULL

Topic: Google Notebook Previous Topic   Next Topic Topic: Damn cool: Rails app running on JVM

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use