Skip to content

Instantly share code, notes, and snippets.

@MiaofeiWang
Last active February 22, 2024 07:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MiaofeiWang/b98854d009e19cdf61db5d1525cccf8e to your computer and use it in GitHub Desktop.
Save MiaofeiWang/b98854d009e19cdf61db5d1525cccf8e to your computer and use it in GitHub Desktop.
Functions for perf testing
name: PerfTestFunctions
description: Functions for perf testing
host: EXCEL
api_set: {}
script:
content: >-
/** @CustomFunction
* @description Simulates rolling a 6-sided die.
* @param dependency Only for triggering chained calc.
* @returns A whole number from 1 to 6.
*/
function roll6sidedWithDependency(dependency: number): number {
return Math.floor(Math.random() * 6) + 1;
}
/**
* Simulate latency and return the number in millisecond.
* @customfunction
* @param {number} latency Average latency In millisecond
* @param {any} dependency Only for triggering chained calc.
* @returns {Promise<number>}
*/
function simulateLatency(latency: number, dependency?: any) {
let simulateLatency = (Math.random() * 2 - 1) * 1000 + latency;
return new Promise((resolve) => {
setTimeout(() => {
resolve(Math.floor(simulateLatency));
}, simulateLatency);
});
}
/**
* Create a simple entity
* @customfunction
* @param {any} dependency Only for triggering chained calc.
* @returns A simple entity.
*/
function createEntity(dependency: any) {
let id = Math.floor(Math.random() * 6) + 1;
let properties = {
TestString: {
type: "String",
basicValue: id.toString()
},
TestDouble: {
type: "Double",
basicValue: 1
}
};
const entity = {
type: "Entity",
text: "Entity " + id.toString(),
properties: properties
};
return entity;
}
/**
* Create a simple entity with specific count of properties
* @customfunction
* @param {number} propertyCount Count of properties
* @param {any} dependency Only for triggering chained calc.
* @returns A simple entity.
*/
function createEntityWithProperties(propertyCount: number, dependency: any)
{
let id = Math.floor(Math.random() * 6) + 1;
let properties = {
};
for (let i = 0; i < propertyCount; i++) {
if (i%2 == 0) {
properties[`Prop${i}`] = {type: "Double", basicValue: 1 };
}
else {
properties[`Prop${i}`] = { type: "String", basicValue: "Test String" };
}
}
const entity = {
type: "Entity",
text: `Entity ${propertyCount} - ${id.toString()}`,
properties: properties
};
return entity;
}
language: typescript
libraries: |
https://appsforoffice.microsoft.com/lib/beta/hosted/office.js
@types/office-js
core-js@2.4.1/client/core.min.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment