# Is faster handling hexadecimal values than handling chars?

**URL:** <https://www.ruby-forum.com/t/is-faster-handling-hexadecimal-values-than-handling-chars/134807>\
**Category:** Ruby\
**Created:** [April 15, 2008, 10:54am UTC](https://www.ruby-forum.com/t/is-faster-handling-hexadecimal-values-than-handling-chars/134807 "2008-04-15T10:54:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ISSSSaki\_Baz\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/51bf81/32.png) [@ISSSSaki\_Baz\_C](https://www.ruby-forum.com/u/ISSSSaki_Baz_C)\
**Post date:** [April 15, 2008, 10:54am UTC](https://www.ruby-forum.com/t/is-faster-handling-hexadecimal-values-than-handling-chars/134807/1 "2008-04-15T10:54:41Z")

</div>

Hi, could I know if it’s faster using hexadecimal values instead of  
charsm in Ruby?  
I mean:

a) char =~ /[\x61-\x7A]|[\x41-\x5A]/

b) char =~ /[A-Z]|[a-z]/

Both are the same, but maybe a) operation is faster than b) ?

Thanks a lot.

---

<div class="post-metadata">

**Author:** ![ISSSSaki\_Baz\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/51bf81/32.png) [@ISSSSaki\_Baz\_C](https://www.ruby-forum.com/u/ISSSSaki_Baz_C)\
**Post date:** [April 15, 2008, 11:05am UTC](https://www.ruby-forum.com/t/is-faster-handling-hexadecimal-values-than-handling-chars/134807/2 "2008-04-15T11:05:23Z")

</div>

2008/4/15, IÃ±aki Baz C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Hi, could I know if it’s faster using hexadecimal values instead of  
> charsm in Ruby?  
> I mean:
> 
> a) char =~ /[\x61-\x7A]|[\x41-\x5A]/
> 
> b) char =~ /[A-Z]|[a-z]/
> 
> Both are the same, but maybe a) operation is faster than b) ?

Sorry, I’ve found Benchmark Class and have tried it:

Benchmark.realtime {‘f’ =~ /[\x61-\x7A]|[\x41-\x5A]/ }  
=\> 1.81198120117188e-05

Benchmark.realtime {‘f’ =~ /[A-Z]|[a-z]/ }  
=\> 1.81198120117188e-05

both give similar results.

Best regards.
