Example GML Format and Native File FormatThe following example shows how the GML format and the native file format for graphs can be used. First a random Parameterized Graph with 1000 nodes and 10000 edges is generated and (dummy) values are assigned to the nodes and edges. The resulting graph is written once in GML format and once in LEDA native format and the time is measured. Afterwards both files are read again and the time is measured again. On the authors machine, writing in GML format is about two times slower than writing in native format. For reading that factor is about 25. #include <LEDA/graph/graph.h> #include <LEDA/graph/graph_gen.h> using namespace leda; int main() { GRAPH<string,string> G; random_graph(G,1000,10000); node v;forall_nodes(v,G) G[v]="node"; edge e;forall_edges(e,G) G[e]="edge"; float t_write_gml=used_time(); G.write_gml("graph_file.gml"); t_write_gml=used_time(t_write_gml); float t_write_gw=used_time(); G.write("graph_file.gw"); t_write_gw=used_time(t_write_gw); G.clear(); float t_read_gml=used_time(); G.read_gml("graph_file.gml"); t_read_gml=used_time(t_read_gml); G.clear(); float t_read_gw=used_time(); G.read("graph_file.gw"); t_read_gw=used_time(t_read_gw); std::cout << "t_write_gml =" << t_write_gml << std::endl; std::cout << "t_read_gml =" << t_read_gml << std::endl; std::cout << "t_write_gw =" << t_write_gw << std::endl; std::cout << "t_read_gw =" << t_read_gw << std::endl; return 0; } |
See also:Manual Entries: |