# Speed of uniq

**URL:** <https://www.ruby-forum.com/t/speed-of-uniq/184299>\
**Category:** Ruby\
**Created:** [February 28, 2010, 3:10pm UTC](https://www.ruby-forum.com/t/speed-of-uniq/184299 "2010-02-28T15:10:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [February 28, 2010, 3:10pm UTC](https://www.ruby-forum.com/t/speed-of-uniq/184299/1 "2010-02-28T15:10:57Z")

</div>

These are general questions about Ruby and not specific to uniq.

(1) How can I tell if a method like uniq is “native” to Ruby. That is,  
it’s not been added as a C extension and/or is not a Ruby method.

(2) A C++ program is producing YAML from a ragged array. As I go  
through each row of the ragged array in the C++ program, I could detect  
if all items are unique … or I can do this in Ruby. I’d prefer to do  
this in Ruby if the cost is not “too high”.

(3) Is there an easy way to find out how uniq is implemented in 1.8 and  
1.9?

---

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [February 28, 2010, 3:30pm UTC](https://www.ruby-forum.com/t/speed-of-uniq/184299/2 "2010-02-28T15:30:51Z")

</div>

On Feb 28, 7:10 am, Ralph S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> (1) How can I tell if a method like uniq is “native” to Ruby. That is, it’s not been added as a C extension and/or is not a Ruby method.

Look in the source code.  
[http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/](http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/)

In this case, look for “rb\_ary\_uniq”.  
[http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/array.c?view=markup](http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/array.c?view=markup)

(You can search for a phrase from the ri documentation to find the  
method.)

> (2) A C++ program is producing YAML from a ragged array. As I go through each row of the ragged array in the C++ program, I could detect if all items are unique … or I can do this in Ruby. I’d prefer to do this in Ruby if the cost is not “too high”.

If this is a question, I don’t understand it.

> (3) Is there an easy way to find out how uniq is implemented in 1.8 and 1.9?

Look in the source code.  
You can find the different branches of Ruby here:  
[http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/](http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/)
