Skip to content

Commit

Permalink
Merge pull request #28 from digitalocean/fix/performance-improvements
Browse files Browse the repository at this point in the history
Performance improvements
  • Loading branch information
fumblehool authored Aug 31, 2023
2 parents d06a867 + 0a7df55 commit 5e7e3b6
Showing 1 changed file with 8 additions and 42 deletions.
50 changes: 8 additions & 42 deletions routes/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
var express = require('express');
var router = express.Router();

var MersenneTwister = require('mersenne-twister');
var generator = new MersenneTwister();

/* GET home page. */
// router.get('/', function(req, res, next) {
// res.render('index', { title: 'Express' });
Expand All @@ -21,16 +24,12 @@ const lorem = new LoremIpsum({
}
});

function randomArticle(seed) {
var MersenneTwister = require('mersenne-twister');
var generator = new MersenneTwister(seed);
function randomArticle() {
var articles = ['a', 'the'];
return articles[Math.floor(generator.random() * articles.length)];
}

function randomNoun(seed) {
var MersenneTwister = require('mersenne-twister');
var generator = new MersenneTwister(seed);
function randomNoun() {
var nouns = ['waste','increase','sky','horn','sweater','head','push','bell',
'passenger','sock','mouth','ant','zoo','holiday','branch','snake','robin',
'knife','part','throne','distribution','women','care','loaf','angle','sleep',
Expand Down Expand Up @@ -129,9 +128,7 @@ function randomNoun(seed) {
return nouns[Math.floor(generator.random() * nouns.length)];
}

function randomVerb(seed) {
var MersenneTwister = require('mersenne-twister');
var generator = new MersenneTwister(seed);
function randomVerb() {
var verbs = ['prays','sprouts','opens','plants','shades','signals','shivers',
'hooks','lies','borrows','punctures','wishes','arrives','watches','hands',
'greets','informs','harasses','crushes','wants','cries','winks','cheats',
Expand Down Expand Up @@ -216,9 +213,7 @@ function randomVerb(seed) {
return verbs[Math.floor(generator.random() * verbs.length)];
}

function randomAjective(seed) {
var MersenneTwister = require('mersenne-twister');
var generator = new MersenneTwister(seed);
function randomAjective() {
var adjectives = ['hushed','teeny-tiny','decisive','long-term','alcoholic',
'alleged','ragged','discreet','ill','devilish','scintillating','furtive',
'unable','honorable','valuable','longing','half','wretched','amused',
Expand Down Expand Up @@ -361,9 +356,7 @@ function randomAjective(seed) {
return adjectives[Math.floor(generator.random() * adjectives.length)];
}

function randomAdverb(seed) {
var MersenneTwister = require('mersenne-twister');
var generator = new MersenneTwister(seed);
function randomAdverb() {
var adverbs = ['dimly','acidly','potentially','judgementally','fervently',
'lively','deeply','beautifully','devotedly','yesterday','tenderly',
'tensely','boastfully','carefully','upward','queasily','basically',
Expand Down Expand Up @@ -455,80 +448,60 @@ function sentenceD(seed) {
}

function sentenceE(seed) {
var MersenneTwister = require('mersenne-twister');
var generator = new MersenneTwister(seed);
sentences = [sentenceA, sentenceB, sentenceC, sentenceD];
return sentences[Math.floor(generator.random() * sentences.length)](seed++) +
' because ' + sentences[Math.floor(generator.random() * sentences.length)](10 + seed++);
}

function sentenceF(seed) {
var MersenneTwister = require('mersenne-twister');
var generator = new MersenneTwister(seed);
sentences = [sentenceA, sentenceB, sentenceC, sentenceD];
return sentences[Math.floor(generator.random() * sentences.length)](seed++) +
' when ' + sentences[Math.floor(generator.random() * sentences.length)](10 + seed++);
}

function sentenceG(seed) {
var MersenneTwister = require('mersenne-twister');
var generator = new MersenneTwister(seed);
sentences = [sentenceA, sentenceB, sentenceC, sentenceD];
return sentences[Math.floor(generator.random() * sentences.length)](seed++) +
' though ' + sentences[Math.floor(generator.random() * sentences.length)](10 + seed++);
}

function sentenceH(seed) {
var MersenneTwister = require('mersenne-twister');
var generator = new MersenneTwister(seed);
sentences = [sentenceA, sentenceB, sentenceC, sentenceD];
return sentences[Math.floor(generator.random() * sentences.length)](seed++) +
' while ' + sentences[Math.floor(generator.random() * sentences.length)](10 + seed++);
}

function sentenceI(seed) {
var MersenneTwister = require('mersenne-twister');
var generator = new MersenneTwister(seed);
sentences = [sentenceA, sentenceB, sentenceC, sentenceD];
return sentences[Math.floor(generator.random() * sentences.length)](seed++) +
', and ' + sentences[Math.floor(generator.random() * sentences.length)](10 + seed++);
}

function sentenceJ(seed) {
var MersenneTwister = require('mersenne-twister');
var generator = new MersenneTwister(seed);
sentences = [sentenceA, sentenceB, sentenceC, sentenceD];
return sentences[Math.floor(generator.random() * sentences.length)](seed++) +
', but ' + sentences[Math.floor(generator.random() * sentences.length)](10 + seed++);
}

function sentenceK(seed) {
var MersenneTwister = require('mersenne-twister');
var generator = new MersenneTwister(seed);
sentences = [sentenceA, sentenceB, sentenceC, sentenceD];
return sentences[Math.floor(generator.random() * sentences.length)](seed++) +
', so ' + sentences[Math.floor(generator.random() * sentences.length)](10 + seed++);
}

function sentenceL(seed) {
var MersenneTwister = require('mersenne-twister');
var generator = new MersenneTwister(seed);
sentences = [sentenceA, sentenceB, sentenceC, sentenceD];
return sentences[Math.floor(generator.random() * sentences.length)](seed++) +
', after ' + sentences[Math.floor(generator.random() * sentences.length)](10 + seed++);
}

function sentenceM(seed) {
var MersenneTwister = require('mersenne-twister');
var generator = new MersenneTwister(seed);
sentences = [sentenceA, sentenceB, sentenceC, sentenceD];
return sentences[Math.floor(generator.random() * sentences.length)](seed++) +
', before ' + sentences[Math.floor(generator.random() * sentences.length)](10 + seed++);
}

function randomSentence(seed) {
var MersenneTwister = require('mersenne-twister');
var generator = new MersenneTwister(seed);
sentences = [sentenceA, sentenceB, sentenceC, sentenceD, sentenceE, sentenceF,
sentenceG, sentenceH, sentenceI, sentenceJ, sentenceK, sentenceL, sentenceM];
sentence = sentences[Math.floor(generator.random() * sentences.length)](seed++);
Expand All @@ -541,8 +514,6 @@ function randomTitle(seed) {
}

function randomParagraph(seed) {
var MersenneTwister = require('mersenne-twister');
var generator = new MersenneTwister(seed);
var sentences = 4 + Math.floor(generator.random() * 5);
var paragraph = [];
for (var i = 0; i < sentences; i++) {
Expand All @@ -552,8 +523,6 @@ function randomParagraph(seed) {
}

function randomParagraphs(seed) {
var MersenneTwister = require('mersenne-twister');
var generator = new MersenneTwister(seed);
var paragraphs = 5 + Math.floor(generator.random() * 100);
var article = [];
for (var i = 0; i < paragraphs; i++) {
Expand All @@ -563,8 +532,6 @@ function randomParagraphs(seed) {
}

function randomLink(seed, hostname) {
var MersenneTwister = require('mersenne-twister');
var generator = new MersenneTwister(seed);
var link = [];
link['href'] = '/' + randomSentence(seed).replace(/ /g, '/').replace(/,/g, '');
var linkSeed = generateSeed(hostname + link['href']);
Expand All @@ -573,7 +540,6 @@ function randomLink(seed, hostname) {
}

function randomLinks(seed, hostname) {
var MersenneTwister = require('mersenne-twister');
var generator = new MersenneTwister(seed+10000);
var linkCount = 5 + Math.floor(generator.random() * 10);
var links = [];
Expand Down

0 comments on commit 5e7e3b6

Please sign in to comment.