What's the difference between {{ siteUrl }} and url()? Both of these things:

1.  {{ siteUrl }}path/to/template
2.  url('path/to/template')


... will generate this:

http://mywebsite.com/path/to/template


So I'm wondering, which method is preferred? Are there any pros/cons of either technique?
The siteUrl global variable is actually set by calling url() without passing anything into it1, so if you're asking about the difference between siteUrl and url() without passing a path to it, you will always get the exact same result. The only difference is that it will be ever so slightly more efficient to use siteUrl since that is a variable that has already been defined for you, whereas Craft will have to go through a bit of logic each time url() is called.

As for where to use which, it's mostly a matter of taste. The only time when siteUrl~"some/path" might differ from url("some/path") is if Craft is not set up to hide index.php in URLS - url() will be smart about how to output URLs with index.php and the path appended after it (either in the query string or path info, depending on the usePathInfp config setting).

There is a greater difference between the two in CP templates, though: in that context url() will automatically add the CP trigger to the path for you.

One last thing worth noting is that url() also provides some arguments for changing the schema (http or https) and appending query string parameters to the URL, whether you pass in a relative site path or a full URL. We've documented those features here: http://buildwithcraft.com/docs/templating/functions#url

1 or more precisely, UrlHelper::getUrl(), the PHP function that url() maps to