user37754: In my code I need to set five pins to output mode. I have the pinMode() statements in my setup. 
I am trying to make my Arduino code run a bit faster, and I came across a tutorial which swaps digitalWrite() for PORTB &= _BV(PB6) (high), and makes it run ~25 times faster.
I'm wondering if there's a similar type of substitution I can do for pinMode(), that will make it run faster as well? Or is pinMode() already a fast command, so I shouldn't worry about it?
Thanks

user4143: The Arduino reference manual has all you need to know:

https://www.arduino.cc/en/Reference/PortManipulation

The register you need is the DDRx register (Data DiRection X). Set a bit to 1 for output and 0 for input. 

user30005: yeah. the corresponding registers are DDRx.
with a little bit of coding, you can easily convert pinMode() to your own, say, mypinMode() that operates on the DDRx directly.
the datasheet is your best friend, as always.

user10794: It isn't worth it for something done once, if you only do it in setup. However if you need to toggle the mode frequently yes it can be done. You sadly haven't said which pins, but assuming they are D2 to D6 (digital pins 2 to 6) on a Mega you can do this to set output mode:
  DDRE |= bit(PE3) | bit(PE4) | bit(PE5); // D5, D2, D3
  DDRG |= bit(PG5); // D4
  DDRH |= bit(PH3); // D6

For input mode you have to "and" in the ones-complement of the bits like this:
  DDRE &= ~(bit(PE3) | bit(PE4) | bit(PE5)); // D5, D2, D3
  DDRG &= ~(bit(PG5)); // D4
  DDRH &= ~(bit(PH3)); // D6

The exact register names are in the datasheet, and the mappings to the pins on your board are in the schematic (available from the Arduino site). The relevant part is this:

The bit numbers are in grey on the left (eg. PE4) and the board pin numbers are in green on the right (eg. 2 is digital pin 2).
The bit macro works similarly to the _BV one you mentioned in your question. It shifts 1 left the required number of bit positions to be in the right place.

A somewhat simpler and more portable solution is to use the digitalWriteFast library which you can download from:
https://github.com/NicksonYap/digitalWriteFast
This uses various compiler tricks to detect if you are using a constant for pinMode and digitalWrite and converts them into the appropriate register manipulation. You just install the library and add Fast to the function names, eg.
pinModeFast (2, OUTPUT);
digitalWriteFast (2, HIGH);


37754: <p>In my code I need to set five pins to output mode. I have the pinMode() statements in my setup. </p>

<p>I am trying to make my Arduino code run a bit faster, and I came across a tutorial which swaps digitalWrite() for PORTB &amp;= _BV(PB6) (high), and makes it run ~25 times faster.</p>

<p>I'm wondering if there's a similar type of substitution I can do for pinMode(), that will make it run faster as well? Or is pinMode() already a fast command, so I shouldn't worry about it?</p>

<p>Thanks</p>
 4143: <p>The Arduino reference manual has all you need to know:</p>

<ul>
<li><a href="https://www.arduino.cc/en/Reference/PortManipulation" rel="nofollow noreferrer">https://www.arduino.cc/en/Reference/PortManipulation</a></li>
</ul>

<p>The register you need is the <code>DDRx</code> register (Data DiRection X). Set a bit to 1 for output and 0 for input. </p>
 30005: <p>yeah. the corresponding registers are DDRx.</p>

<p>with a little bit of coding, you can easily convert pinMode() to your own, say, mypinMode() that operates on the DDRx directly.</p>

<p>the datasheet is your best friend, as always.</p>
 10794: <p>It isn't worth it for something done once, if you only do it in <code>setup</code>. However if you need to toggle the mode frequently yes it can be done. You sadly haven't said which pins, but assuming they are D2 to D6 (digital pins 2 to 6) <em>on a Mega</em> you can do this to set <strong>output</strong> mode:</p>

<pre><code>  DDRE |= bit(PE3) | bit(PE4) | bit(PE5); // D5, D2, D3
  DDRG |= bit(PG5); // D4
  DDRH |= bit(PH3); // D6
</code></pre>

<p>For <strong>input</strong> mode you have to "and" in the ones-complement of the bits like this:</p>

<pre><code>  DDRE &amp;= ~(bit(PE3) | bit(PE4) | bit(PE5)); // D5, D2, D3
  DDRG &amp;= ~(bit(PG5)); // D4
  DDRH &amp;= ~(bit(PH3)); // D6
</code></pre>

<p>The exact register names are in the datasheet, and the mappings to the pins on your board are in the schematic (available from <a href="https://store.arduino.cc/usa/arduino-mega-2560-rev3" rel="nofollow noreferrer">the Arduino site</a>). The relevant part is this:</p>

<p><a href="https://i.stack.imgur.com/gVL5w.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gVL5w.png" alt="Mega pins D0 to D7"></a></p>

<p>The bit numbers are in grey on the left (eg. PE4) and the board pin numbers are in green on the right (eg. 2 is digital pin 2).</p>

<p>The <code>bit</code> macro works similarly to the <code>_BV</code> one you mentioned in your question. It shifts <code>1</code> left the required number of bit positions to be in the right place.</p>

<hr>

<p>A somewhat simpler and more portable solution is to use the digitalWriteFast library which you can download from:</p>

<p><a href="https://github.com/NicksonYap/digitalWriteFast" rel="nofollow noreferrer">https://github.com/NicksonYap/digitalWriteFast</a></p>

<p>This uses various compiler tricks to detect if you are using a constant for <code>pinMode</code> and <code>digitalWrite</code> and converts them into the appropriate register manipulation. You just install the library and add <code>Fast</code> to the function names, eg.</p>

<pre><code>pinModeFast (2, OUTPUT);
digitalWriteFast (2, HIGH);
</code></pre>
