Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(benchmarks): rename benchmark folder for consistency (#26948)
- Loading branch information
Showing
31 changed files
with
612 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Typescript v1 declaration files | ||
typings/ | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# dotenv environment variable files | ||
.env* | ||
|
||
# gatsby files | ||
.cache/ | ||
public | ||
|
||
# Mac files | ||
.DS_Store | ||
|
||
# Yarn | ||
yarn-error.log | ||
.pnp/ | ||
.pnp.js | ||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
gendata.csv |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Markdown Benchmark; CSV+text version | ||
|
||
This is a baseline benchmark for tracking CSV plaintext performance in the Gabe project. | ||
|
||
This will produce the same site as `gabe-markdown` without using any markdown. It also generates one giant csv file containing all the data, rather than an individual file per page. | ||
|
||
The site can generate an arbitrary amount of super simple pages. Each page has a small header, a quote, and two small paragraphs of random text. No images, because that's a fixed cost we're not interested in. | ||
|
||
## Install | ||
|
||
Run `yarn` or `npm install` | ||
|
||
## Usage | ||
|
||
You can start a benchmark run like this: | ||
|
||
```shell | ||
N=1000 M=2 yarn bench | ||
``` | ||
|
||
- `N=1000`: instructs the run to build a site of 1000 pages | ||
- `M=2`: instructs nodejs to use up to 2gb of memory for its long term storage | ||
- Deletes generates files from previous run | ||
- Generates a new `gendata.csv` file containing `N` rows, each row being one page with pseudo-random content | ||
- Runs `gatsby clean` | ||
- Runs `gatsby build` | ||
|
||
The default `yarn bench` will build 512 pages with 1gb memory. |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module.exports = { | ||
siteMetadata: { | ||
title: `Gatsby CSV Markdown Benchmark for Gabe`, | ||
description: "A blog like no other blog", | ||
author: "Bob the Blogger", | ||
}, | ||
plugins: [ | ||
`gatsby-transformer-csv`, | ||
`gatsby-transformer-remark`, | ||
{ | ||
resolve: `gatsby-source-filesystem`, | ||
options: { | ||
path: __dirname + '/gendata.csv', | ||
}, | ||
}, | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
const path = require(`path`) | ||
const { createFilePath } = require(`gatsby-source-filesystem`) | ||
|
||
exports.createPages = async ({ graphql, actions }) => { | ||
const { createPage } = actions | ||
const blogPost = path.resolve(`./src/templates/blog-post.js`) | ||
const result = await graphql( | ||
` | ||
{ | ||
allGendataCsv (sort: { fields: [date], order: DESC }) { | ||
edges { | ||
node { | ||
id | ||
slug | ||
title | ||
} | ||
} | ||
} | ||
} | ||
` | ||
) | ||
|
||
if (result.errors) { | ||
throw result.errors | ||
} | ||
|
||
// Create blog posts pages. | ||
const posts = result.data.allGendataCsv.edges | ||
|
||
posts.forEach((post, index) => { | ||
const previous = index === posts.length - 1 ? null : posts[index + 1].node | ||
const next = index === 0 ? null : posts[index - 1].node | ||
|
||
createPage({ | ||
path: post.node.slug, | ||
component: blogPost, | ||
context: { | ||
slug: post.node.slug, | ||
id: post.node.id, | ||
previous, | ||
next, | ||
}, | ||
}) | ||
}) | ||
} | ||
|
||
// Use this to keep in sync with markdown benchmark. TODO: drop this and see the difference. | ||
exports.onCreateNode = ({ node, actions, getNode }) => { | ||
const { createNodeField } = actions | ||
|
||
if (node.internal.type === `DataCsv`) { | ||
createNodeField({ | ||
name: `slug2`, | ||
node, | ||
value: './' + node.slug, | ||
}) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
const fs = require("fs") | ||
const path = require("path") | ||
const faker = require(`faker`) | ||
|
||
console.log("Start of gen") | ||
|
||
const N = parseInt(process.env.N, 10) || 100 | ||
const FILE = path.resolve("gendata.csv") | ||
|
||
console.log("Now generating " + N + " articles into", FILE) | ||
fs.writeFileSync(FILE, "articleNumber,title,description,slug,date,tags,body\n") | ||
|
||
function createArticle(n) { | ||
const title = faker.lorem.sentence() | ||
const slug = faker.helpers.slugify(title).toLowerCase() | ||
const desc = faker.lorem.sentence() | ||
const date = faker.date.recent(1000).toISOString().slice(0, 10) | ||
const tags = faker.random | ||
.words(3) | ||
.split(` `) | ||
.map(w => `"${w}"`) | ||
.join(`, `) | ||
fs.appendFileSync( | ||
FILE, | ||
[ | ||
// 'a','b','c','d','e','f', 'g' | ||
String(n), | ||
title, | ||
desc, | ||
slug, | ||
date, | ||
tags, | ||
` | ||
<h1>${title}</h1> | ||
<blockquote>${desc}</blockquote> | ||
<p>${faker.lorem.paragraphs(1)}</p> | ||
<p>${faker.lorem.paragraphs(1)}</p> | ||
`, | ||
] | ||
.map(s => | ||
s | ||
.trim() | ||
// Need to escape newlines and commas | ||
.replace(/,/g, "\\,") | ||
.replace(/\n/g, "") // html don't care about newlines | ||
) | ||
.join(",") + "\n" | ||
) | ||
} | ||
|
||
for (let i = 0; i < N; ++i) { | ||
createArticle(i) | ||
} | ||
|
||
console.log("Finished generating " + N + " articles into", FILE) | ||
console.log("End of gen") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"name": "gabe-csv-text", | ||
"private": true, | ||
"description": "Benchmark site for testing baseline csv+plaintext perf", | ||
"author": "Peter van der Zee <pvdz@github>", | ||
"version": "0.1.0", | ||
"license": "MIT", | ||
"scripts": { | ||
"bench": "rm -rf generated_articles; gatsby clean; N=${N:-512} node gen.js; CI=1 node --max_old_space_size=${M:-2}000 node_modules/.bin/gatsby build", | ||
"build": "gatsby build", | ||
"clean": "gatsby clean", | ||
"develop": "gatsby develop", | ||
"format": "prettier --write \"**/*.{js,jsx,json,md}\"" | ||
}, | ||
"devDependencies": { | ||
"prettier": "2.0.4" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/gatsbyjs/gatsby/tree/master/benchmarks/" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/gatsbyjs/gatsby/issues" | ||
}, | ||
"keywords": [ | ||
"gatsby", | ||
"benchmark", | ||
"markdown" | ||
], | ||
"dependencies": { | ||
"faker": "^4.1.0", | ||
"gatsby": "^2", | ||
"gatsby-source-filesystem": "^2", | ||
"gatsby-transformer-csv": "^2", | ||
"react": "^16.12.0", | ||
"react-dom": "^16.12.0" | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import React from "react" | ||
import { Link, graphql } from "gatsby" | ||
|
||
import Bio from "../components/bio" | ||
import Layout from "../components/layout" | ||
|
||
class BlogIndex extends React.Component { | ||
render() { | ||
const { data } = this.props | ||
const siteTitle = data.site.siteMetadata.title | ||
const posts = data.allGendataCsv.edges | ||
|
||
return ( | ||
<Layout location={this.props.location} title={siteTitle}> | ||
<Bio /> | ||
{posts.map(({ node }) => { | ||
const title = node.title || node.slug | ||
return ( | ||
<article key={node.slug}> | ||
<header> | ||
<h3 | ||
style={{ | ||
marginBottom: '5px', | ||
}} | ||
> | ||
<Link style={{ boxShadow: `none` }} to={node.slug}> | ||
{title} | ||
</Link> | ||
</h3> | ||
<small>{node.date}</small> | ||
</header> | ||
<section> | ||
<p | ||
dangerouslySetInnerHTML={{ | ||
__html: node.description, | ||
}} | ||
/> | ||
</section> | ||
</article> | ||
) | ||
})} | ||
</Layout> | ||
) | ||
} | ||
} | ||
|
||
export default BlogIndex | ||
|
||
export const pageQuery = graphql` | ||
query { | ||
site { | ||
siteMetadata { | ||
title | ||
} | ||
} | ||
allGendataCsv(limit: 100) { | ||
edges { | ||
node { | ||
articleNumber | ||
title | ||
description | ||
slug | ||
date | ||
tags | ||
body | ||
} | ||
} | ||
} | ||
} | ||
` |
Oops, something went wrong.