<!-- Include dexie.js -->
<script src="https://unpkg.com/dexie@^2.0.0-beta/dist/dexie.js"></script>
<!-- Some HTML for the log window -->
<a href="http://dexie.org/docs/API-Reference" target="_new">Dexie API Reference (new tab)</a>
<h3>Log</h3>
<textarea id="log"></textarea>
<p id="safari-version" style="display:none;">
This browser denies indexedDB access from iframes.
<a href="https://fiddle.jshell.net/dfahlander/xf2zrL4p/show" target="_top">Click here to open it directly without any iframe.</a>
</p>
<!-- Just a simple log function... -->
<script>
function log(txt) {document.getElementById('log').value+=txt+"\n";}
</script>
CSS
textarea#log
{
width: 100%;
height: 1000px;
}
JavaScript
//
// Define database
//
var db = new Dexie("raindrops");
db.version(1).stores({
raindrops: 'id,position',
});
log ("Using Dexie v" + Dexie.semVer);
//
// Prepare data
//
var drops = [];
for (var i=1;i<=10000;++i) {
drops.push({
id: i,
position: Math.random(),
someData: {
someText: "some value",
someNumber: Math.random()
}
});
}
//
// Test Performance
//
testPerformance().catch(err => log(err));
async function testPerformance() {
try {
//
// Open Database
//
await db.open();
log(``);
log(`put() (with transaction)`);
log(`=========`);
log(`Let's put() 10,000 documents in a single transaction! ...`);
let time = performance.now();
await db.transaction('rw', db.raindrops, async () => {
for (const drop of drops) {
await db.raindrops.put(drop);
}
});
log(`put() operations done. Took ${Math.round(performance.now() - time)} milliseconds.`);
log(``);
log(`put() (without transaction)`);
log(`=========`);
await db.raindrops.clear();
log(`Let's put() 10,000 documents without using a transaction! ...`);
time = performance.now();
for (const drop of drops) {
await db.raindrops.put(drop);
}
log(`put() operations done. Took ${Math.round(performance.now() - time)} milliseconds.`);
log(``);
log(`bulkPut()`);
log(`=========`);
await db.raindrops.clear();
log(`Let's put 10,000 documents in a single bulkPut()! ...`);
time = performance.now();
await db.raindrops.bulkPut(drops);
log(`bulkPut() operation done. Took ${Math.round(performance.now() - time)} milliseconds.`);
log(``);
log(``);
log(`add() (with transaction)`);
log(`=========`);
await db.raindrops.clear();
log(`Let's add() 10,000 documents in a single transaction! ...`);
await db.transaction('rw', db.raindrops, async () => {
for (const drop of drops) {
await db.raindrops.add(drop);
}
});
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.