不要怂,就是干,撸起袖子干!

Performance.ejs 1.97 KB
<script type="text/javascript" charset="utf-8">
  document.observe("dom:loaded", function() {
    buildNavigation([], ["<br />", "<a href=\"/examples/Count\">Count</a>",
"<a href=\"/examples/DefaultValues\">Default values</a>",
"<a href=\"/examples/fetchAssociations\">fetchAssociations</a>",
"<a href=\"/examples/MethodPassing\">MethodPassing</a>",
"<a href=\"/examples/Performance\">Performance</a>",
"<a href=\"/examples/SequelizeWithOptions\">SequelizeWithOptions</a>",
"<a href=\"/examples/ChainQueries\">Using the chainQueries function</a>",
"<a href=\"/examples/UsingMultipleModelFiles\">UsingMultipleModelFiles</a>",
"<a href=\"/examples/Associations\">Working with associations</a>"], { seperator: ' ' })
  })
</script>

<div>
  <a name="sequelize"></a>
  <h1>Performance</h1>
  <p></p>
</div>


  <div class="seperator"></div>

  <div>
    <a name="app.js"></a>
    <h2>app.js</h2>
    <p>
      
      <pre>var Sequelize = require(__dirname + &quot;/../../lib/sequelize/Sequelize&quot;).Sequelize,
    sequelize = new Sequelize(&quot;sequelize_test&quot;, &quot;root&quot;, null, { disableLogging: true })

var Person = sequelize.define('person', { name: Sequelize.STRING })

Sequelize.chainQueries([{drop: sequelize}, {sync: sequelize}], function() {
  var start   = Date.now(),
      count   = 10000,
      queries = []
  
  for(var i = 0; i &lt; count; i++) {
    var p = new Person({name: 'someone'})
    queries.push({ save: p })
  }
  
  Sequelize.Helper.log(&quot;Begin to save &quot; + count + &quot; items!&quot;)
  Sequelize.chainQueries(queries, function() {
    Sequelize.Helper.log(&quot;Saving &quot; + count + &quot; items took: &quot; + (Date.now() - start) + &quot;ms&quot;)
    
    start   = Date.now()
    Sequelize.Helper.log(&quot;Will now read them from the database:&quot;)
    Person.findAll(function(persons) {
      Sequelize.Helper.log(&quot;Reading &quot; + persons.length + &quot; items took: &quot; + (Date.now() - start) + &quot;ms&quot;)
    })
  })
})</pre>
    </p>
</div>