perf-internal-a.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. var Sequelize = require('./index')
  2. , AbstractQuery = require('./lib/dialects/abstract/query')
  3. , Model = require('./lib/model')
  4. , fs = require('fs')
  5. , data = JSON.parse(fs.readFileSync('perf.json'))
  6. , sequelize = new Sequelize('sequelize_test', 'sequelize_test', '', {
  7. dialect: 'postgres',
  8. host: '172.17.0.2',
  9. logging: false
  10. })
  11. , AREAS = ['area1', 'area2', 'area3']
  12. , DAMAGE_MAX = 3;
  13. var Report = sequelize.define('Report', {
  14. area: {
  15. type: Sequelize.STRING,
  16. allowNull: false,
  17. validate: {
  18. isIn: [AREAS]
  19. }
  20. },
  21. damageLevel: {
  22. type: Sequelize.INTEGER,
  23. allowNull: false,
  24. defaultValue: 0,
  25. validate: {
  26. isInt: {
  27. msg: "Must be an integer"
  28. },
  29. min: 0,
  30. max: DAMAGE_MAX
  31. }
  32. },
  33. description: {
  34. type: Sequelize.TEXT,
  35. allowNull: true,
  36. validate: {
  37. notEmpty: true
  38. }
  39. }
  40. });
  41. var Location = sequelize.define('Location', {
  42. latitude: {
  43. type: Sequelize.FLOAT(53),
  44. allowNull: false,
  45. validate: {
  46. isFloat: {
  47. msg: "Must be a floating point number"
  48. },
  49. min: -90.0,
  50. max: 90.0
  51. }
  52. },
  53. longitude: {
  54. type: Sequelize.FLOAT(53),
  55. allowNull: false,
  56. validate: {
  57. isFloat: {
  58. msg: "Must be a floating point number"
  59. },
  60. min: -180.0,
  61. max: 180.0
  62. }
  63. },
  64. altitude: {
  65. type: Sequelize.FLOAT(53),
  66. allowNull: true,
  67. defaultValue: null
  68. }
  69. });
  70. var Employee = sequelize.define('Employee', {
  71. name: {
  72. type: Sequelize.STRING,
  73. allowNull: false
  74. }
  75. });
  76. Location.hasMany(Report);
  77. Report.belongsTo(Location);
  78. Employee.hasMany(Report);
  79. Report.hasMany(Employee);
  80. /*{
  81. include: [
  82. {model: Report, include: [Employee]}
  83. ]
  84. }*/
  85. var tableNames = {};
  86. tableNames[Location.tableName] = true;
  87. /*var options = {
  88. include: [
  89. {model: Report, include: [Employee]}
  90. ]
  91. };
  92. Model.$validateIncludedElements.call(Location, options, tableNames);*/
  93. var start = new Date();
  94. var result;
  95. /*function printStatus(fn) {
  96. switch(%GetOptimizationStatus(fn)) {
  97. case 1: console.log("Function is optimized"); break;
  98. case 2: console.log("Function is not optimized"); break;
  99. case 3: console.log("Function is always optimized"); break;
  100. case 4: console.log("Function is never optimized"); break;
  101. case 6: console.log("Function is maybe deoptimized"); break;
  102. }
  103. }
  104. //Fill type-info
  105. result = AbstractQuery.$groupJoinData(data, {
  106. model: Location,
  107. includeMap: options.includeMap,
  108. includeNames: options.includeNames
  109. }, {
  110. checkExisting: true
  111. });
  112. console.log("---------------");
  113. console.log("---------------");
  114. console.log("---------------");
  115. %OptimizeFunctionOnNextCall(AbstractQuery.$groupJoinData);*/
  116. //The next call
  117. var options = {
  118. include: [
  119. {model: Report, include: [Employee]}
  120. ]
  121. };
  122. Model.$validateIncludedElements.call(Location, options, tableNames);
  123. for (var i = 0; i < 10; i++) {
  124. result = AbstractQuery.$groupJoinData(data, {
  125. model: Location,
  126. includeMap: options.includeMap,
  127. includeNames: options.includeNames
  128. }, {
  129. checkExisting: true
  130. });
  131. }
  132. //Check
  133. console.log("$groupJoinData");
  134. //printStatus(AbstractQuery.$groupJoinData);
  135. console.log("finish, took " + (new Date() - start));
  136. console.log(result.length);
  137. //console.log(JSON.stringify(result[result.length - 1], null, '\t'));