Elegance of a database API matters to the programmer. Frequently, database APIs provide rudimentary functionality without thinking about the programmer's desire for elegant yet efficient syntax. This article discusses API design that is both elegant and efficient. It does so, firstly, by comparing the Lua APIs for two separate databases, Redis and YottaDB. Secondly, it benchmarks both databases using each API to implement a 3n+1 sequence generator (of Collatz Conjecture fame) against both databases. It will cover the eccentricities of the Lua APIs, the databases, and the nifty choice of benchmark tool. Finally, the benchmark results are presented showing the respective speed benefits of each database's unique design.
翻译:数据库API的优雅性对程序员至关重要。当前许多数据库API仅提供基础功能,未能充分考虑程序员对语法既优雅又高效的诉求。本文探讨了兼顾优雅与效率的API设计方法。首先,通过对比Redis与YottaDB两个独立数据库的Lua API展开分析;其次,采用3n+1序列生成器(源自著名的考拉兹猜想)作为基准测试工具,分别通过两种API对两个数据库进行性能评估。文中将详细解析Lua API的特性差异、数据库的独有机制,以及基准测试工具的精妙设计。最后,通过基准测试结果展示两种数据库独特设计所带来的各自速度优势。