Change:
I'm using s as keys in a BtreeMap. I have to look up the map ~15 million times per second (10G ethernet line rate). Ipv4Addr cmp() compiles to this on my system (linux x86-64, rustc 1.10.0-nightly ( 2016-05-21)) Which seems kinda inefficient for a thing which is basically u32. I guess part of the reason is the which converts it to an array(!) first. I copied the definition and implemented Ord like this: It's about 10 times faster on my .
Nice find! Want to send a PR for this? Looks like something that'd be more than welcome :)

Discussion:
use marker::Sized; <del> /// A common trait for cloning an object. </del> <ins> /// A common trait for cloning an object. Differs from `Copy` in that you can /// define `Clone` to run arbitrary code, while you are not allowed to override /// the implementation of `Copy` that only does a `memcpy`. </ins> /// <del> /// This trait can be used with `#[derive]`. </del> <ins> /// Since `Clone` is more general than `Copy`, you can automatically make anything /// `Copy` be `Clone` as well. /// /// ## Derivable /// /// This trait can be used with `#[derive]` if all fields are `Clone`. The `derive`d /// implementation of `clone()` calls `clone()` on each field. /// /// ## How can I implement `Clone`? </ins> /// /// Types that are `Copy` should have a trivial implementation of `Clone`. More formally: /// if `T: Copy`, `x: T`, and `y: &T`, then `let x = y.clone();` is equivalent to `let x = *y;`. /// Manual implementations should be careful to uphold this invariant; however, unsafe code /// must not rely on it to ensure memory safety. <ins> /// /// An example is an array holding more than 32 of a type that is `Clone`; the standard library /// only implements `Clone` up until arrays of size 32. In this case, the implementation of /// `Clone` cannot be `derive`d, but can be implemented as: /// /// ``` /// #[derive(Copy)] /// struct Stats { ///    frequencies: [i32; 100], /// } /// /// impl Clone for Stats { ///     fn clone(&self) -> Self { *self } /// } /// ``` </ins> #[stable(feature = "rust1", since = "1.0.0")] pub trait Clone : Sized { /// Returns a copy of the value.

/// symmetrically and transitively: if `T: PartialEq<U>` and `U: PartialEq<V>` /// then `U: PartialEq<T>` and `T: PartialEq<V>`. /// <ins> /// ## Derivable /// /// This trait can be used with `#[derive]`. When `derive`d on structs, two /// instances are equal if all fields are equal, and non equal if any fields /// are not equal. When `derive`d on enums, each variant is equal to itself /// and not equal to the other variants. /// /// ## How can I implement `PartialEq`? /// </ins> /// PartialEq only requires the `eq` method to be implemented; `ne` is defined /// in terms of it by default. Any manual implementation of `ne` *must* respect /// the rule that `eq` is a strict inverse of `ne`; that is, `!(a == b)` if and /// only if `a != b`. /// <del> /// This trait can be used with `#[derive]`. </del> <ins> /// An example implementation for a domain in which two books are considered /// the same book if their ISBN matches, even if the formats differ: /// /// ``` /// enum BookFormat { Paperback, Hardback, Ebook } /// struct Book { ///     isbn: i32, ///     format: BookFormat, /// } /// impl PartialEq for Book { ///     fn eq(&self, other: &Self) -> bool { ///         self.isbn == other.isbn ///     } /// } /// /// let b1 = Book { isbn: 3, format: BookFormat::Paperback }; /// let b2 = Book { isbn: 3, format: BookFormat::Ebook }; /// let b3 = Book { isbn: 10, format: BookFormat::Paperback }; /// /// assert!(b1 == b2); /// assert!(b1 != b3); /// ``` </ins> /// /// # Examples ///

/// This property cannot be checked by the compiler, and therefore `Eq` implies /// `PartialEq`, and has no extra methods. /// <del> /// This trait can be used with `#[derive]`. </del> <ins> /// ## Derivable /// /// This trait can be used with `#[derive]`. When `derive`d, because `Eq` has /// no extra methods, it is only informing the compiler that this is an /// equivalence relation rather than a partial equivalence relation. Note that /// the `derive` strategy requires all fields are `PartialEq`, which isn't /// always desired. /// /// ## How can I implement `Eq`? /// /// If you cannot use the `derive` strategy, specify that your type implements /// `Eq`, which has no methods: /// /// ``` /// enum BookFormat { Paperback, Hardback, Ebook } /// struct Book { ///     isbn: i32, ///     format: BookFormat, /// } /// impl PartialEq for Book { ///     fn eq(&self, other: &Self) -> bool { ///         self.isbn == other.isbn ///     } /// } /// impl Eq for Book {} /// ``` </ins> #[stable(feature = "rust1", since = "1.0.0")] pub trait Eq: PartialEq<Self> { // FIXME #13101: this method is used solely by #[deriving] to

/// - total and antisymmetric: exactly one of `a < b`, `a == b` or `a > b` is true; and /// - transitive, `a < b` and `b < c` implies `a < c`. The same must hold for both `==` and `>`. /// <ins> /// ## Derivable /// </ins> /// This trait can be used with `#[derive]`. When `derive`d, it will produce a lexicographic /// ordering based on the top-to-bottom declaration order of the struct's members. <ins> /// /// ## How can I implement `Ord`? /// /// `Ord` requires that the type also be `PartialOrd` and `Eq` (which requires `PartialEq`). /// /// Then you must define an implementation for `cmp`. You may find it useful to use /// `cmp` on your type's fields. /// /// Here's an example where you want to sort people by height only, disregarding `id` /// and `name`: /// /// ``` /// use std::cmp::Ordering; /// #[derive(Eq)] /// struct Person { ///     id: u32, ///     name: String, ///     height: u32, /// } /// /// impl Ord for Person { ///     fn cmp(&self, other: &Self) -> Ordering { ///         self.height.cmp(&other.height) ///     } /// } /// /// impl PartialOrd for Person { ///     fn partial_cmp(&self, other: &Self) -> Option<Ordering> { ///         Some(self.cmp(other)) ///     } /// } /// /// impl PartialEq for Person { ///     fn eq(&self, other: &Self) -> bool { ///         self.height == other.height ///     } /// } /// ``` </ins> #[stable(feature = "rust1", since = "1.0.0")] pub trait Ord: Eq + PartialOrd<Self> { /// This method returns an `Ordering` between `self` and `other`.

/// transitively: if `T: PartialOrd<U>` and `U: PartialOrd<V>` then `U: PartialOrd<T>` and `T: /// PartialOrd<V>`. /// <ins> /// ## Derivable /// /// This trait can be used with `#[derive]`. When `derive`d, it will produce a lexicographic /// ordering based on the top-to-bottom declaration order of the struct's members. /// /// ## How can I implement `Ord`? /// </ins> /// PartialOrd only requires implementation of the `partial_cmp` method, with the others generated /// from default implementations. ///

/// total order. For example, for floating point numbers, `NaN < 0 == false` and `NaN >= 0 == /// false` (cf. IEEE 754-2008 section 5.11). /// <del> /// This trait can be used with `#[derive]`. When `derive`d, it will produce an ordering /// based on the top-to-bottom declaration order of the struct's members. </del> <ins> /// `PartialOrd` requires your type to be `PartialEq`. /// /// If your type is `Ord`, you can implement `partial_cmp` by using `cmp`: /// /// ``` /// impl PartialOrd for Person { ///     fn partial_cmp(&self, other: &Self) -> Option<Ordering> { ///         Some(self.cmp(other)) ///     } /// } /// ``` /// /// You may also find it useful to use `partial_cmp` on your type`s fields. Here /// is an example of `Person` types who have a floating-point `height` field that /// is the only field to be used for sorting: /// /// ``` /// use std::cmp::Ordering; /// /// struct Person { ///     id: u32, ///     name: String, ///     height: f64, /// } /// /// impl PartialOrd for Person { ///     fn partial_cmp(&self, other: &Self) -> Option<Ordering> { ///         self.height.partial_cmp(&other.height) ///     } /// } /// /// impl PartialEq for Person { ///     fn eq(&self, other: &Self) -> bool { ///         self.height == other.height ///     } /// } /// ``` </ins> /// /// # Examples ///

/// /// [module]: ../../std/fmt/index.html /// <del> /// This trait can be used with `#[derive]`. </del> <ins> /// This trait can be used with `#[derive]` if all fields implement `Debug`. When /// `derive`d for structs, it will use the name of the `struct`, then `{`, then a /// comma-separated list of each field's name and `Debug` value, then `}`. For /// `enum`s, it will use the name of the variant and, if applicable, `(`, then the /// `Debug` values of the fields, then `)`. </ins> /// /// # Examples ///

/// In other words, if two keys are equal, their hashes should also be equal. /// `HashMap` and `HashSet` both rely on this behavior. /// <del> /// This trait can be used with `#[derive]`. </del> <ins> /// ## Derivable /// /// This trait can be used with `#[derive]` if all fields implement `Hash`. /// When `derive`d, the resulting hash will be the combination of the values /// from calling `.hash()` on each field. /// /// ## How can I implement `Hash`? /// /// If you need more control over how a value is hashed, you need to implement /// the trait `Hash`: /// /// ``` /// use std::hash::{Hash, Hasher}; /// /// struct Person { ///     id: u32, ///     name: String, ///     phone: u64, /// } /// /// impl Hash for Person { ///     fn hash<H: Hasher>(&self, state: &mut H) { ///         self.id.hash(state); ///         self.phone.hash(state); ///     } /// } /// ``` </ins> #[stable(feature = "rust1", since = "1.0.0")] pub trait Hash { /// Feeds this value into the state given, updating the hasher as necessary.

/// the trait `Copy` may not be implemented for this type; field `points` does not implement `Copy` /// ``` /// <ins> /// ## When can my type _not_ be `Copy`? /// /// Some types can't be copied safely. For example, copying `&mut T` would create an aliased /// mutable reference, and copying `String` would result in two attempts to free the same buffer. /// /// Generalizing the latter case, any type implementing `Drop` can't be `Copy`, because it's /// managing some resource besides its own `size_of::<T>()` bytes. /// /// ## When should my type be `Copy`? /// /// Generally speaking, if your type _can_ implement `Copy`, it should. There's one important thing /// to consider though: if you think your type may _not_ be able to implement `Copy` in the future, /// then it might be prudent to not implement `Copy`. This is because removing `Copy` is a breaking /// change: that second example would fail to compile if we made `Foo` non-`Copy`. /// /// ## Derivable /// /// This trait can be used with `#[derive]` if all of its components implement `Copy` and the type /// implements `Clone`. The implementation will copy the bytes of each field using `memcpy`. /// </ins> /// ## How can I implement `Copy`? /// /// There are two ways to implement `Copy` on your type:

/// /// There is a small difference between the two: the `derive` strategy will also place a `Copy` /// bound on type parameters, which isn't always desired. <del> /// /// ## When can my type _not_ be `Copy`? /// /// Some types can't be copied safely. For example, copying `&mut T` would create an aliased /// mutable reference, and copying `String` would result in two attempts to free the same buffer. /// /// Generalizing the latter case, any type implementing `Drop` can't be `Copy`, because it's /// managing some resource besides its own `size_of::<T>()` bytes. /// /// ## When should my type be `Copy`? /// /// Generally speaking, if your type _can_ implement `Copy`, it should. There's one important thing /// to consider though: if you think your type may _not_ be able to implement `Copy` in the future, /// then it might be prudent to not implement `Copy`. This is because removing `Copy` is a breaking /// change: that second example would fail to compile if we made `Foo` non-`Copy`. /// /// # Derivable /// /// This trait can be used with `#[derive]`. </del> #[stable(feature = "rust1", since = "1.0.0")] #[lang = "copy"] pub trait Copy : Clone {