forked from opencog/benchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request opencog#8 from ngeiswei/merge-opencog-to-singnet
Merge opencog -> singnet
- Loading branch information
Showing
14 changed files
with
931 additions
and
39 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
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
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
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
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
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
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,105 @@ | ||
/* | ||
* addlink_bm.cc | ||
* | ||
* Copyright (C) 2020 OpenCog Foundation | ||
* All Rights Reserved | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License v3 as | ||
* published by the Free Software Foundation and including the exceptions | ||
* at http://opencog.org/wiki/Licenses | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program; if not, write to: | ||
* Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
|
||
#include <benchmark/benchmark.h> | ||
|
||
#include <opencog/atoms/base/Node.h> | ||
#include <opencog/atoms/base/Link.h> | ||
#include <opencog/atomspace/AtomSpace.h> | ||
|
||
#include "benchmark.h" | ||
|
||
using namespace opencog; | ||
|
||
static void BM_AddLink(benchmark::State& state) | ||
{ | ||
const size_t num_to_add = state.range(0); | ||
AtomSpace* as = new AtomSpace(); | ||
|
||
// 101 and 233 are prime numbers. Thus, the links will interconnect | ||
// to form some kind of nice polytope. | ||
const size_t number_of_atoms = state.range(0); | ||
std::vector<Handle> atoms(number_of_atoms); | ||
for (size_t i = 0; i < number_of_atoms; ++i) | ||
atoms[i] = createLink(LIST_LINK, | ||
createNode(CONCEPT_NODE, "barfology" + std::to_string(i%101)), | ||
createNode(CONCEPT_NODE, "blingometry" + std::to_string(i%233))); | ||
|
||
size_t i = 0; | ||
size_t j = 0; | ||
for (auto _ : state) | ||
{ | ||
if (j%3 == 0) // we are creating 3 atoms per pop... | ||
as->add_atom(atoms[i++ % number_of_atoms]); | ||
j++; | ||
|
||
if (num_to_add < j) | ||
{ | ||
as->clear(); | ||
j = 0; | ||
} | ||
} | ||
delete as; | ||
} | ||
|
||
// Cannot go higher than 17 because the benchmark doesn't | ||
// iterate enough times. | ||
BENCHMARK(BM_AddLink)->Arg(2<<9)->Arg(2<<16)->Arg(2<<17); | ||
|
||
static void BM_CreateAddLink(benchmark::State& state) | ||
{ | ||
const size_t num_to_add = state.range(0); | ||
AtomSpace* as = new AtomSpace(); | ||
|
||
std::vector<std::string> aname(101); | ||
std::vector<std::string> bname(233); | ||
for (size_t i = 0; i < 101; ++i) | ||
aname[i] = "barfology" + std::to_string(i); | ||
for (size_t i = 0; i < 233; ++i) | ||
bname[i] = "blingometry" + std::to_string(i); | ||
|
||
size_t i = 0; | ||
size_t j = 0; | ||
for (auto _ : state) | ||
{ | ||
if (j%3 == 0) // we are creating 3 atoms per pop... | ||
{ | ||
// Make a copy so that move constructore works right. | ||
as->add_link(LIST_LINK, | ||
as->add_node(CONCEPT_NODE, std::string({aname[i % 101]})), | ||
as->add_node(CONCEPT_NODE, std::string({bname[i % 233]}))); | ||
i++; | ||
} | ||
j++; | ||
|
||
if (num_to_add < j) | ||
{ | ||
as->clear(); | ||
j = 0; | ||
} | ||
} | ||
delete as; | ||
} | ||
|
||
// Cannot go higher than 17 because the benchmark doesn't | ||
// iterate enough times. | ||
BENCHMARK(BM_CreateAddLink)->Arg(2<<9)->Arg(2<<16)->Arg(2<<17); |
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,85 @@ | ||
/* | ||
* addnode_bm.cc | ||
* | ||
* Copyright (C) 2020 OpenCog Foundation | ||
* All Rights Reserved | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License v3 as | ||
* published by the Free Software Foundation and including the exceptions | ||
* at http://opencog.org/wiki/Licenses | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program; if not, write to: | ||
* Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
|
||
#include <benchmark/benchmark.h> | ||
|
||
#include <opencog/atoms/base/Node.h> | ||
#include <opencog/atomspace/AtomSpace.h> | ||
|
||
#include "benchmark.h" | ||
|
||
using namespace opencog; | ||
|
||
static void BM_AddNode(benchmark::State& state) | ||
{ | ||
AtomSpace* as = new AtomSpace(); | ||
|
||
size_t seed = 0; | ||
const size_t number_of_nodes = state.range(0); | ||
std::vector<Handle> nodes(number_of_nodes); | ||
for (size_t i = 0; i < number_of_nodes; ++i) | ||
nodes[i] = createNode(CONCEPT_NODE, get_unique_name("barfology", seed)); | ||
|
||
size_t i = 0; | ||
for (auto _ : state) | ||
{ | ||
as->add_atom(nodes[i++]); | ||
if (number_of_nodes <= i) | ||
{ | ||
as->clear(); | ||
i = 0; | ||
} | ||
} | ||
delete as; | ||
} | ||
|
||
// Cannot go higher than 17 because the benchmark doesn't | ||
// iterate enough times. | ||
BENCHMARK(BM_AddNode)->Arg(2<<9)->Arg(2<<16)->Arg(2<<17); | ||
|
||
static void BM_CreateAddNode(benchmark::State& state) | ||
{ | ||
AtomSpace* as = new AtomSpace(); | ||
|
||
size_t seed = 0; | ||
const size_t number_of_names = state.range(0); | ||
std::vector<std::string> names(number_of_names); | ||
for (size_t i = 0; i < number_of_names; ++i) | ||
names[i] = get_unique_name("barfology", seed); | ||
|
||
size_t i = 0; | ||
for (auto _ : state) | ||
{ | ||
// Make a copy so that move constructore works right. | ||
as->add_node(CONCEPT_NODE, std::string({names[i++]})); | ||
if (number_of_names <= i) | ||
{ | ||
as->clear(); | ||
i = 0; | ||
} | ||
} | ||
delete as; | ||
} | ||
|
||
// Cannot go higher than 17 because the benchmark doesn't | ||
// iterate enough times. | ||
BENCHMARK(BM_CreateAddNode)->Arg(2<<9)->Arg(2<<16)->Arg(2<<17); |
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,55 @@ | ||
/* | ||
* atomspace_bm.cc | ||
* | ||
* Copyright (C) 2020 OpenCog Foundation | ||
* All Rights Reserved | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License v3 as | ||
* published by the Free Software Foundation and including the exceptions | ||
* at http://opencog.org/wiki/Licenses | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program; if not, write to: | ||
* Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
|
||
#include <benchmark/benchmark.h> | ||
|
||
#include <opencog/atoms/base/Node.h> | ||
#include <opencog/atomspace/AtomSpace.h> | ||
|
||
#include "benchmark.h" | ||
|
||
using namespace opencog; | ||
|
||
static void BM_AtomSpace_Basic(benchmark::State& state) | ||
{ | ||
AtomSpace* as; | ||
|
||
for (auto _ : state) | ||
{ | ||
as = new AtomSpace(); | ||
delete as; | ||
} | ||
} | ||
BENCHMARK(BM_AtomSpace_Basic); | ||
|
||
static void BM_AtomSpace_OneNode(benchmark::State& state) | ||
{ | ||
AtomSpace* as; | ||
|
||
for (auto _ : state) | ||
{ | ||
as = new AtomSpace(); | ||
as->add_node(CONCEPT_NODE, "foobariffic"); | ||
delete as; | ||
} | ||
} | ||
BENCHMARK(BM_AtomSpace_OneNode); |
Oops, something went wrong.