#!/usr/bin/perl # # $Id: octalize 2593 2003-12-21 00:35:53Z jmates $ # # The author disclaims all copyrights and releases this document into # the public domain. use Benchmark qw(cmpthese); $input = 'ABC'; $input_long = 'this is a test of the nuclear destruct system on this computer, or in other words a long string of text to see whether any differences in speed result from operating on really long strings of text'; cmpthese( -10, { split_s => sub { $result = join '', map { '\\\\' . ord } split //, $input }, regex_s => sub { ($result = $input) =~ s/(.)/'\\\\'.ord $1/ge }, split_l => sub { $result = join '', map { '\\\\' . ord } split //, $input_long }, regex_l => sub { ($result = $input_long) =~ s/(.)/'\\\\'.ord $1/ge }, } ); __END__