diff --git a/mps/code/djb.c b/mps/code/djb.c new file mode 100644 index 00000000000..04030ed2242 --- /dev/null +++ b/mps/code/djb.c @@ -0,0 +1,52 @@ +/* djb.c -- "DJ" benchmark template + * $Id$ + * + * This file is intended to be included in other programs that define + * + * DJRUN function to call to run the template + * ALLOC(p, s) allocate block of size s and assign to p + * FREE(p, s) free previously-allocated block at p of size s + */ + +#include +#include "testlib.h" + +static void DJRUN(unsigned niter, /* iterations */ + unsigned npass, /* passes over blocks */ + unsigned nblocks, /* number of blocks */ + unsigned sshift, /* log2 max block size in words */ + double prob) /* probability per pass of acting */ +{ + struct {void *p; size_t s;} *blocks = alloca(sizeof(*blocks) * nblocks); + unsigned i, j, k; + + for (k = 0; k < nblocks; ++k) { + blocks[k].p = NULL; + } + + for (i = 0; i < niter; ++i) { + for (j = 0; j < npass; ++j) { + for (k = 0; k < nblocks; ++k) { + if (rnd() % 16384 < prob * 16384) { + if (blocks[k].p == NULL) { + size_t s = rnd() % ((sizeof(void *) << (rnd() % sshift)) - 1); + void *p = NULL; + if (s > 0) ALLOC(p, s); + blocks[k].p = p; + blocks[k].s = s; + } else { + FREE(blocks[k].p, blocks[k].s); + blocks[k].p = NULL; + } + } + } + } + + for (k = 0; k < nblocks; ++k) { + if (blocks[k].p) { + FREE(blocks[k].p, blocks[k].s); + blocks[k].p = NULL; + } + } + } +} diff --git a/mps/code/djban.c b/mps/code/djban.c new file mode 100644 index 00000000000..860c4b6bf1f --- /dev/null +++ b/mps/code/djban.c @@ -0,0 +1,93 @@ +/* djban.c -- "DJ" Benchmark on ANSI C library + * $Id$ + */ + +#include +#include +#include + +#define DJRUN dj_malloc +#define ALLOC(p, s) do { p = malloc(s); } while(0) +#define FREE(p, s) do { free(p); } while(0) +#include "djb.c" +#undef DJRUN +#undef ALLOC +#undef FREE + +#include "mps.c" + +static mps_arena_t arena; +static mps_pool_t pool; +static mps_ap_t ap; + +#define DJRUN dj_alloc +#define ALLOC(p, s) do { mps_alloc(&p, pool, s); } while(0) +#define FREE(p, s) do { mps_free(pool, p, s); } while(0) +#include "djb.c" +#undef DJRUN +#undef ALLOC +#undef FREE + +#define ALIGN_UP(s, a) (((s) + ((a) - 1)) & ~((a) - 1)) + +#define DJRUN dj_reserve +#define ALLOC(p, s) \ + do { \ + size_t _s = ALIGN_UP(s, (size_t)MPS_PF_ALIGN); \ + mps_reserve(&p, ap, _s); \ + mps_commit(ap, p, _s); \ + } while(0) +#define FREE(p, s) do { mps_free(pool, p, s); } while(0) +#include "djb.c" +#undef DJRUN +#undef ALLOC +#undef FREE + +#define MUST(expr) \ + do { \ + mps_res_t res = (expr); \ + if (res != MPS_RES_OK) { \ + fprintf(stderr, #expr " returned %d\n", res); \ + exit(EXIT_FAILURE); \ + } \ + } while(0) + + +typedef void (*dj_t)(unsigned, unsigned, unsigned, unsigned, double); + +static void wrap(dj_t dj, const char *name) +{ + clock_t start, finish; + + start = clock(); + dj(100, 1000, 1000, 18, 0.2); + finish = clock(); + + printf("%s: %g\n", name, (double)(finish - start) / CLOCKS_PER_SEC); +} + + +static void arena_wrap(dj_t dj, mps_class_t pool_class, const char *name) +{ + MPS_ARGS_BEGIN(args) { + MPS_ARGS_ADD(args, MPS_KEY_ARENA_SIZE, 256ul * 1024 * 1024); /* FIXME: Why is there no default? */ + MPS_ARGS_DONE(args); + MUST(mps_arena_create_k(&arena, mps_arena_class_vm(), args)); + } MPS_ARGS_END(args); + MUST(mps_pool_create_k(&pool, arena, pool_class, mps_args_none)); + MUST(mps_ap_create_k(&ap, pool, mps_args_none)); + wrap(dj, name); + mps_ap_destroy(ap); + mps_pool_destroy(pool); + mps_arena_destroy(arena); +} + + +int main(void) { + arena_wrap(dj_reserve, mps_class_mvt(), "mvt"); + arena_wrap(dj_reserve, mps_class_mvff(), "mvff"); + arena_wrap(dj_alloc, mps_class_mv(), "mv"); + wrap(dj_malloc, "an"); + + return EXIT_SUCCESS; +} diff --git a/mps/code/mps.xcodeproj/project.pbxproj b/mps/code/mps.xcodeproj/project.pbxproj index d735f470044..250704e7b03 100644 --- a/mps/code/mps.xcodeproj/project.pbxproj +++ b/mps/code/mps.xcodeproj/project.pbxproj @@ -25,6 +25,8 @@ buildPhases = ( ); dependencies = ( + 313794A4176CDD7D00BCFAEC /* PBXTargetDependency */, + 313794A2176CDD7900BCFAEC /* PBXTargetDependency */, 3104AFF6156D37BC000A585A /* PBXTargetDependency */, 3114A644156E94FB001E0AA3 /* PBXTargetDependency */, 3104AFF8156D37BE000A585A /* PBXTargetDependency */, @@ -204,6 +206,8 @@ 3124CAFA156BE82000753214 /* fmtno.c in Sources */ = {isa = PBXBuildFile; fileRef = 3124CACC156BE4C200753214 /* fmtno.c */; }; 3124CAFB156BE82000753214 /* testlib.c in Sources */ = {isa = PBXBuildFile; fileRef = 31EEAC9E156AB73400714D05 /* testlib.c */; }; 3124CAFC156BE82900753214 /* libmps.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 31EEABFB156AAF9D00714D05 /* libmps.a */; }; + 3137949E176CC3B100BCFAEC /* djban.c in Sources */ = {isa = PBXBuildFile; fileRef = 3137949D176CC3B100BCFAEC /* djban.c */; }; + 3137949F176CD02700BCFAEC /* testlib.c in Sources */ = {isa = PBXBuildFile; fileRef = 31EEAC9E156AB73400714D05 /* testlib.c */; }; 3150AE53156ABA2500A6E22A /* libmps.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 31EEABFB156AAF9D00714D05 /* libmps.a */; }; 317B3C2B1731830100F9A469 /* arg.c in Sources */ = {isa = PBXBuildFile; fileRef = 317B3C2A1731830100F9A469 /* arg.c */; }; 31A47BA4156C1E130039B1C2 /* mps.c in Sources */ = {isa = PBXBuildFile; fileRef = 31A47BA3156C1E130039B1C2 /* mps.c */; }; @@ -654,6 +658,20 @@ remoteGlobalIDString = 3114A6C5156E9815001E0AA3; remoteInfo = mpseventcnv; }; + 313794A1176CDD7900BCFAEC /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 31EEABDA156AAE9E00714D05 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 31FCAE0917692403008C034C; + remoteInfo = scheme; + }; + 313794A3176CDD7D00BCFAEC /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 31EEABDA156AAE9E00714D05 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 31379492176CC34D00BCFAEC; + remoteInfo = djban; + }; 31A47BA9156C210D0039B1C2 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 31EEABDA156AAE9E00714D05 /* Project object */; @@ -1039,6 +1057,15 @@ ); runOnlyForDeploymentPostprocessing = 1; }; + 31379491176CC34D00BCFAEC /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = /usr/share/man/man1/; + dstSubfolderSpec = 0; + files = ( + ); + runOnlyForDeploymentPostprocessing = 1; + }; 31D6000B156D3CB200337B26 /* CopyFiles */ = { isa = PBXCopyFilesBuildPhase; buildActionMask = 2147483647; @@ -1236,6 +1263,9 @@ 3124CAE4156BE6D500753214 /* fmthe.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = fmthe.c; sourceTree = ""; }; 3124CAEB156BE7F300753214 /* amcss */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = amcss; sourceTree = BUILT_PRODUCTS_DIR; }; 3124CAF5156BE81100753214 /* amcss.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = amcss.c; sourceTree = ""; }; + 31379493176CC34D00BCFAEC /* djban */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = djban; sourceTree = BUILT_PRODUCTS_DIR; }; + 3137949D176CC3B100BCFAEC /* djban.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = djban.c; sourceTree = ""; }; + 313794A0176CD21F00BCFAEC /* djb.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = djb.c; sourceTree = ""; }; 317B3C2A1731830100F9A469 /* arg.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = arg.c; sourceTree = ""; }; 31A47BA3156C1E130039B1C2 /* mps.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = mps.c; sourceTree = ""; }; 31A47BA5156C1E5E0039B1C2 /* ssixi3.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = ssixi3.c; sourceTree = ""; }; @@ -1559,6 +1589,13 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 31379490176CC34D00BCFAEC /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; 31D6000A156D3CB200337B26 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -1714,6 +1751,15 @@ name = Tests; sourceTree = ""; }; + 3137948E176CC0F800BCFAEC /* Benchmarks */ = { + isa = PBXGroup; + children = ( + 3137949D176CC3B100BCFAEC /* djban.c */, + 313794A0176CD21F00BCFAEC /* djb.c */, + ); + name = Benchmarks; + sourceTree = ""; + }; 31A47BA6156C1E620039B1C2 /* I3 */ = { isa = PBXGroup; children = ( @@ -1745,6 +1791,7 @@ 31EEABD8156AAE9E00714D05 = { isa = PBXGroup; children = ( + 3137948E176CC0F800BCFAEC /* Benchmarks */, 2D07B97B163705E400DB751B /* libsqlite3.dylib */, 3114A6D6156E9846001E0AA3 /* Tools */, 31A47BA8156C1E930039B1C2 /* MPS */, @@ -1796,6 +1843,7 @@ 2291A5E3175CB05F001D4920 /* exposet0 */, 224CC799175E1821002FF81B /* fotest */, 31FCAE0A17692403008C034C /* scheme */, + 31379493176CC34D00BCFAEC /* djban */, ); name = Products; sourceTree = ""; @@ -2503,6 +2551,23 @@ productReference = 3124CAEB156BE7F300753214 /* amcss */; productType = "com.apple.product-type.tool"; }; + 31379492176CC34D00BCFAEC /* djban */ = { + isa = PBXNativeTarget; + buildConfigurationList = 31379499176CC34D00BCFAEC /* Build configuration list for PBXNativeTarget "djban" */; + buildPhases = ( + 3137948F176CC34D00BCFAEC /* Sources */, + 31379490176CC34D00BCFAEC /* Frameworks */, + 31379491176CC34D00BCFAEC /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = djban; + productName = djban; + productReference = 31379493176CC34D00BCFAEC /* djban */; + productType = "com.apple.product-type.tool"; + }; 31D6000C156D3CB200337B26 /* awluthe */ = { isa = PBXNativeTarget; buildConfigurationList = 31D60014156D3CB200337B26 /* Build configuration list for PBXNativeTarget "awluthe" */; @@ -2724,6 +2789,7 @@ 2D604B9B16514B1A003AAF46 /* mpseventtxt */, 22CDE8EF16E9E97D00366D0A /* testrun */, 31FCAE0917692403008C034C /* scheme */, + 31379492176CC34D00BCFAEC /* djban */, ); }; /* End PBXProject section */ @@ -3062,6 +3128,15 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 3137948F176CC34D00BCFAEC /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 3137949E176CC3B100BCFAEC /* djban.c in Sources */, + 3137949F176CD02700BCFAEC /* testlib.c in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 31D60009156D3CB200337B26 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -3450,6 +3525,16 @@ target = 3114A6C5156E9815001E0AA3 /* mpseventcnv */; targetProxy = 3114A6D4156E9839001E0AA3 /* PBXContainerItemProxy */; }; + 313794A2176CDD7900BCFAEC /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 31FCAE0917692403008C034C /* scheme */; + targetProxy = 313794A1176CDD7900BCFAEC /* PBXContainerItemProxy */; + }; + 313794A4176CDD7D00BCFAEC /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 31379492176CC34D00BCFAEC /* djban */; + targetProxy = 313794A3176CDD7D00BCFAEC /* PBXContainerItemProxy */; + }; 31A47BAA156C210D0039B1C2 /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = 31EEABFA156AAF9D00714D05 /* mps */; @@ -4166,6 +4251,28 @@ }; name = Release; }; + 3137949A176CC34D00BCFAEC /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 3137949B176CC34D00BCFAEC /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; + 3137949C176CC34D00BCFAEC /* WE */ = { + isa = XCBuildConfiguration; + buildSettings = { + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = WE; + }; 318387EB15DC30CC008E4EA0 /* WE */ = { isa = XCBuildConfiguration; buildSettings = { @@ -5110,6 +5217,15 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + 31379499176CC34D00BCFAEC /* Build configuration list for PBXNativeTarget "djban" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 3137949A176CC34D00BCFAEC /* Debug */, + 3137949B176CC34D00BCFAEC /* Release */, + 3137949C176CC34D00BCFAEC /* WE */, + ); + defaultConfigurationIsVisible = 0; + }; 31D60014156D3CB200337B26 /* Build configuration list for PBXNativeTarget "awluthe" */ = { isa = XCConfigurationList; buildConfigurations = ( @@ -5208,6 +5324,7 @@ 31FCAE1217692403008C034C /* WE */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ };