#!/usr/bin/env perl use strict; use warnings; use Inline 'C'; use Time::HiRes qw( time ); my $buf = chr(1) x 1e6;; my $s = time; my $out = interleave( $buf, chr(0) ); print time() - $s, "\n"; $buf = chr(1) x 1e6;; $s = time; $out = join( chr(0), unpack '(A1)*', $buf ) .chr(0); print time() - $s, "\n"; __END__ __C__ char *interleave(char *in, char other) { char *outbuf = malloc( sizeof(char) * strlen( in ) * 2 + 1); char *outp = outbuf; char *p = in; while( *p ) { *outp++ = *p++; *outp++ = other; } *outp = '\0'; return outbuf; }