A couple weeks ago, the SharePoint product team announced the SharePoint Test Data Load Tool. You can find a brief article on TechNet and download the tool from CodePlex (as well as the full source code!)
I have used a preliminary release of this tool on a recent project, and it's absolutely invaluable when you need to automatically generate large datasets (i.e. sites, document libraries, documents, pages, etc.) for performance testing. Of course, you could leverage the SharePoint API and write the provisioning code yourself, but this tool will allow you to use XML files to describe the data you want to generate, which makes the task much easier.
For example, here's how you can create a hundred sites, and assign unique permissions to each of them:
<WSSDWLib> <ForLoop name="i" start="1" end="100"> <Webs name="site$i$" title="Site $i$" template="SiteBase.stp" uniqueperms="true"> <RoleAssigns name="SNCF\user$i$" roledefs="Reader" /> </Webs> </ForLoop></WSSDWLib>
Of course, you can also describe much more complex sets of actions; here's another one I used:
<WSSDWLib> <SetVar count="0" /> <ForLoop name="j" values="Sites1-10,Sites11-20,Sites21-30,Sites31-40,Sites41-50,Sites51-60,Sites61-70,Sites71-80,Sites81-90,Sites91-100"> <Webs name="$j$" openmode="openexisting"> <ForLoop name="i" start="1" end="10"> <SetVarEqu n="%count%+$i$" /> <Webs name="Site%n%" openmode="openexisting"> <Lists name="Documents" openmode="openexisting"> <Files sourcedir="C:\wsscollab\wssdataloading\WSSCollabCPData\testfiles\OfficeDocs" checkin="true" publish="true" approve="true" /> </Lists> </Webs> </ForLoop> </Webs> <SetVarEqu count="%count%+10" /> </ForLoop></WSSDWLib>
It iterates over a two-level hierarchy of a hundred sites, opens the Documents doclib in each of them, uploads a bunch of files, and then checks them in, approves them, and publishes them.
You will find many more examples in the samples on CodePlex.